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