Salome HOME
refs #1048
[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,
305                                         QString& statMess) const;
306 #endif
307
308 public:      
309   // Public methods to work with Calculation services
310
311   /**
312    * Returns altitude for given point.
313    * \param thePoint the point to examine
314    * \return result altitude value
315    */
316   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const;
317
318   /**
319    * Returns altitude for given point on given region.
320    * \param thePoint the point to examine
321    * \param theRegion reference region to check
322    * \return result altitude value
323    */
324   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                    thePoint,
325                                                        const Handle(HYDROData_Region)& theRegion,
326                                                        int theMethod = 0) const;
327
328   /**
329    * Returns altitude for given point on given zone.
330    * \param thePoint the point to examine
331    * \param theZone reference zone to check
332    * \return result altitude value
333    */
334   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                  thePoint,
335                                                        const Handle(HYDROData_Zone)& theZone,
336                                                        int theMethod = 0) const;
337
338   /**
339    * Returns strickler coefficient for given point.
340    * \param thePoint the point to examine
341    * \return result strickler coefficient
342    */
343   HYDRODATA_EXPORT double GetStricklerCoefficientForPoint( const gp_XY& thePoint ) const;
344
345   HYDRODATA_EXPORT std::vector<double> GetStricklerCoefficientForPoints(const std::vector<gp_XY>& thePoints,
346                                                                         double DefValue,
347                                                                         bool UseMax ) const;
348
349   /**
350    * Returns altitudes for given points on given region.
351    * \param thePoints the points to examine
352    * \param theRegion reference region to check
353    * \return result altitude value
354    */
355   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
356     const NCollection_Sequence<gp_XY>& thePoints,
357     const Handle(HYDROData_Region)&    theRegion,
358     int theMethod = 0) const;
359
360   /**
361    * Returns altitudes for given points on given zone.
362    * \param thePoints the points to examine
363    * \param theZone reference zone to check
364    * \return result altitude value
365    */
366   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
367     const NCollection_Sequence<gp_XY>& thePoints,
368     const Handle(HYDROData_Zone)&      theZone,
369     int theMethod = 0) const;
370
371   /**
372    * Returns region to which the point is belongs.
373    * \param thePoint the point to examine
374    * if it is needed to search Land Cover region
375    * \return result region
376    */
377   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegionFromPoint( const gp_XY& thePoint ) const;
378
379   /**
380    * Returns zone to which the point is belongs.
381    * \param thePoint the point to examine
382    * if it is needed to search Land Cover zone
383    * \return result zone
384    */
385   HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZoneFromPoint( const gp_XY& thePoint ) const;
386
387   /**
388    * Returns classification of point for given zone.
389    * \param thePoint the point to examine
390    * \param theZone the zone to examine
391    * \return result classification
392    */
393   HYDRODATA_EXPORT virtual PointClassification GetPointClassification(
394     const gp_XY&                  thePoint,
395     const Handle(HYDROData_Zone)& theZone ) const;
396
397   HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode );
398   HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const;
399
400   HYDRODATA_EXPORT void ClearRules( HYDROData_CalculationCase::DataTag theDataTag,
401                                     const bool theIsSetToUpdate = true );
402   HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Entity)&     theObject1,
403                                  HYDROData_PriorityType              thePriority,
404                                  const Handle(HYDROData_Entity)&     theObject2,
405                                  HYDROData_Zone::MergeType theMergeType,
406                                  HYDROData_CalculationCase::DataTag  theDataTag );
407   HYDRODATA_EXPORT bool GetRule( int theIndex, 
408                                  Handle(HYDROData_Entity)&           theObject1,
409                                  HYDROData_PriorityType&             thePriority,
410                                  Handle(HYDROData_Entity)&           theObject2,
411                                  HYDROData_Zone::MergeType& theMergeType,
412                                  HYDROData_CalculationCase::DataTag& theDataTag ) const;
413
414   HYDRODATA_EXPORT QString DumpRules() const;
415
416   HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const;
417
418 private:
419
420   /**
421    * Add new one region for calculation case.
422    * The new region is added into the list of reference regions.
423    */
424   Handle(HYDROData_Region) addNewRegion( const Handle(HYDROData_Document)& theDoc,
425                                          const QString& thePrefixOrName,
426                                          bool isPrefix = true );
427
428   /**
429    * Add new one split edges group for calculation case.
430    */
431   Handle(HYDROData_SplitShapesGroup) addNewSplitGroup( const QString& theName );
432
433   /**
434    * Exports the given faces as shell and the given groups to GEOM module.
435    * \param theGeomEngine GEOM module engine
436    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
437    * \param theFaces the list of faces to make shell 
438    * \param theSplitGroups the list of groups
439    * \return true in case of success
440    */
441 #ifndef LIGHT_MODE
442   bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
443                SALOMEDS::Study_ptr                           theStudy,
444                const NCollection_IndexedDataMap<TopoDS_Shape, QString>& aFacesToName,
445                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
446                QString& theGeomObjEntry ) const;
447 #endif
448   
449   void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
450                          const HYDROData_SplitToZonesTool::SplitDataList& theZones );
451   void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
452                           const HYDROData_SplitToZonesTool::SplitDataList& theZones );
453
454   void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
455                             const HYDROData_SplitToZonesTool::SplitDataList& theEdges );
456
457   void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
458
459   void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" );
460
461   void UpdateRegionsNames( const HYDROData_SequenceOfObjects& theRegions,
462                            const QString& theOldCaseName,
463                            const QString& theName );
464   
465   void DumpRegionsToPython( QStringList&                       theResList,
466                             const QString&                     thePyScriptPath,
467                             MapOfTreatedObjects&               theTreatedObjects,
468                             const HYDROData_SequenceOfObjects& theRegions ) const;
469
470 protected:
471   friend class HYDROData_Iterator;
472
473   /**
474    * Creates new object in the internal data structure. Use higher level objects 
475    * to create objects with real content.
476    */
477   HYDRODATA_EXPORT HYDROData_CalculationCase();
478
479   /**
480    * Destructs properties of the object and object itself, removes it from the document.
481    */
482   HYDRODATA_EXPORT ~HYDROData_CalculationCase();
483
484   void DumpSampleMeshing( QStringList& theScript,
485                           const QString& theStudyName,
486                           const QString& theGeomShapeName,
487                           const QString& theMeshName ) const;
488
489 private:
490   HYDROData_Warning myLastWarning;
491 };
492
493 #endif