Salome HOME
Merge remote-tracking branch 'origin/BR_IMPROVEMENTS' into BR_v14_rc
[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 // IDL includes
29 #include <SALOMEconfig.h>
30 #include CORBA_SERVER_HEADER(GEOM_Gen)
31
32 class gp_XY;
33
34 class TopoDS_Shape;
35 class TopoDS_Shell;
36 class TopTools_ListOfShape;
37
38 class Handle(HYDROData_Object);
39 class Handle(HYDROData_Region);
40 class Handle(HYDROData_Zone);
41 class Handle(HYDROData_PolylineXY);
42 class Handle(HYDROData_ShapesGroup);
43 class Handle(HYDROData_SplittedShapesGroup);
44 class Handle(HYDROData_Document);
45
46 DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
47
48
49 /**\class HYDROData_CalculationCase
50  * \brief Calculation case is defined by selection of Geometry objects with or without \93Zone of water\94.
51  *
52  */
53 class HYDROData_CalculationCase : public HYDROData_Entity
54 {
55 public:
56
57   enum PointClassification
58   {
59     POINT_OUT,  ///< point is out of zone face
60     POINT_IN,   ///< point is inside of zone face
61     POINT_ON    ///< point is on the edge of zone face
62   };
63
64   enum AssignmentMode
65   {
66     MANUAL = 0,
67     AUTOMATIC,
68   };
69
70 public:
71
72   /**
73    * Enumeration of tags corresponding to the persistent object parameters.
74    */
75   enum DataTag
76   {
77     DataTag_First = HYDROData_Entity::DataTag_First + 100, ///< first tag, to reserve
78     DataTag_GeometryObject,   ///< reference geometry objects
79     DataTag_ChildRegion,      ///< child regions
80     DataTag_Region,           ///< reference regions
81     DataTag_Polyline,         ///< reference boundary polyline
82     DataTag_GeometryGroup,    ///< reference geometry groups
83     DataTag_SplittedGroups,   ///< reference splitted groups
84     DataTag_CustomRules,      ///< custom rules
85     DataTag_AssignmentMode,   ///< assignment mode
86   };
87
88 public:
89
90   DEFINE_STANDARD_RTTI(HYDROData_CalculationCase);
91
92   /**
93    * Returns the kind of this object. Must be redefined in all objects of known type.
94    */
95   HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_CALCULATION; }
96
97   /**
98    * Updates the name of this object.
99    * Reimplemented to update the names of regions, zones and splitted groups.
100    */
101   HYDRODATA_EXPORT virtual void SetName( const QString& theName );
102
103   /**
104    * Dump Calculation object to Python script representation.
105    */
106   HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const;
107
108   /**
109    * Update the calcualtion case object.
110    * Call this method whenever you made changes for object data.
111    */
112   HYDRODATA_EXPORT virtual void Update();
113
114   /**
115    * Returns the list of all reference objects of this object.
116    */
117   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetAllReferenceObjects() const;
118
119 public:      
120   // Public methods to work with Calculation
121
122   /**
123    * Add new one reference geometry object for calculation case.
124    */
125   HYDRODATA_EXPORT virtual bool AddGeometryObject( const Handle(HYDROData_Object)& theObject );
126
127   /**
128    * Returns all reference geometry objects of calculation case.
129    */
130   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryObjects() const;
131
132   /**
133    * Removes reference geometry object from calculation case.
134    */
135   HYDRODATA_EXPORT virtual void RemoveGeometryObject( const Handle(HYDROData_Object)& theObject );
136
137   /**
138    * Removes all reference geometry objects from calculation case.
139    */
140   HYDRODATA_EXPORT virtual void RemoveGeometryObjects();
141
142
143   /**
144    * Add new one reference geometry group for calculation case.
145    */
146   HYDRODATA_EXPORT virtual bool AddGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
147
148   /**
149    * Returns all reference geometry groups of calculation case.
150    */
151   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetGeometryGroups() const;
152
153   /**
154    * Removes reference geometry group from calculation case.
155    */
156   HYDRODATA_EXPORT virtual void RemoveGeometryGroup( const Handle(HYDROData_ShapesGroup)& theGroup );
157
158   /**
159    * Removes all reference geometry groups from calculation case.
160    */
161   HYDRODATA_EXPORT virtual void RemoveGeometryGroups();
162
163
164   /**
165    * Sets reference boundary polyline object for calculation case.
166    */
167   HYDRODATA_EXPORT virtual void SetBoundaryPolyline( const Handle(HYDROData_PolylineXY)& thePolyline );
168
169   /**
170    * Returns reference boundary polyline object of calculation case.
171    */
172   HYDRODATA_EXPORT virtual Handle(HYDROData_PolylineXY) GetBoundaryPolyline() const;
173
174   /**
175    * Remove reference boundary polyline object from calculation case.
176    */
177   HYDRODATA_EXPORT virtual void RemoveBoundaryPolyline();
178
179
180   /**
181    * Add new one child region for calculation case.
182    * The new region is added into the list of reference regions.
183    * The label of theZone is changed during this operation
184    * because of new region becomes the new parent for this zone.
185    */
186   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) AddNewRegion( const Handle(HYDROData_Zone)& theZone );
187
188
189   /**
190    * Add new one reference region for calculation case.
191    * The label of theRegion is changed in case if old parent is not this calculation.
192    */
193   HYDRODATA_EXPORT virtual bool AddRegion( const Handle(HYDROData_Region)& theRegion );
194
195   /**
196    * Returns all reference regions of calculation case.
197    */
198   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetRegions() const;
199
200   /**
201    * Updates names of regions to correct order.
202    */
203   HYDRODATA_EXPORT virtual void UpdateRegionsOrder();
204
205   /**
206    * Removes reference region from calculation case.
207    */
208   HYDRODATA_EXPORT virtual void RemoveRegion( const Handle(HYDROData_Region)& theRegion );
209
210   /**
211    * Removes all reference regions from calculation case.
212    */
213   HYDRODATA_EXPORT virtual void RemoveRegions();
214
215   
216   /**
217    * Returns all reference geometry groups of calculation case.
218    */
219   HYDRODATA_EXPORT virtual HYDROData_SequenceOfObjects GetSplittedGroups() const;
220
221   /**
222    * Removes all reference geometry groups from calculation case.
223    */
224   HYDRODATA_EXPORT virtual void RemoveSplittedGroups();
225
226   /**
227    * Exports the calculation case data (shell and groups) to GEOM module.
228    * \param theStudyId the id of the study where the GEOM module should be used for export
229    * \return the entry of the GEOM object (empty string in the case of error)
230    */
231   HYDRODATA_EXPORT virtual QString Export( int theStudyId ) const;
232
233   /**
234    * Exports the calculation case data (shell and groups) to GEOM module.
235    * \param theGeomEngine GEOM module engine
236    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
237    * \return true in case of success
238    */
239   HYDRODATA_EXPORT virtual bool Export( GEOM::GEOM_Gen_var  theGeomEngine,
240                                         SALOMEDS::Study_ptr theStudy,
241                                         QString& theGeomObjEntry ) const;
242
243 public:      
244   // Public methods to work with Calculation services
245
246   /**
247    * Returns altitude for given point.
248    * \param thePoint the point to examine
249    * \return result altitude value
250    */
251   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const;
252
253   /**
254    * Returns altitude for given point on given region.
255    * \param thePoint the point to examine
256    * \param theRegion reference region to check
257    * \return result altitude value
258    */
259   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                    thePoint,
260                                                        const Handle(HYDROData_Region)& theRegion ) const;
261
262   /**
263    * Returns altitude for given point on given zone.
264    * \param thePoint the point to examine
265    * \param theZone reference zone to check
266    * \return result altitude value
267    */
268   HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY&                  thePoint,
269                                                        const Handle(HYDROData_Zone)& theZone ) const;
270
271   /**
272    * Returns altitudes for given points on given region.
273    * \param thePoints the points to examine
274    * \param theRegion reference region to check
275    * \return result altitude value
276    */
277   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
278     const NCollection_Sequence<gp_XY>& thePoints,
279     const Handle(HYDROData_Region)&    theRegion ) const;
280
281   /**
282    * Returns altitudes for given points on given zone.
283    * \param thePoints the points to examine
284    * \param theZone reference zone to check
285    * \return result altitude value
286    */
287   HYDRODATA_EXPORT virtual NCollection_Sequence<double> GetAltitudesForPoints( 
288     const NCollection_Sequence<gp_XY>& thePoints,
289     const Handle(HYDROData_Zone)&      theZone ) const;
290
291   /**
292    * Returns region to which the point is belongs.
293    * \param thePoint the point to examine
294    * \return result region
295    */
296   HYDRODATA_EXPORT virtual Handle(HYDROData_Region) GetRegionFromPoint( const gp_XY& thePoint ) const;
297
298   /**
299    * Returns zone to which the point is belongs.
300    * \param thePoint the point to examine
301    * \return result zone
302    */
303   HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZoneFromPoint( const gp_XY& thePoint ) const;
304
305   /**
306    * Returns classification of point for given zone.
307    * \param thePoint the point to examine
308    * \param theZone the zone to examine
309    * \return result classification
310    */
311   HYDRODATA_EXPORT virtual PointClassification GetPointClassification(
312     const gp_XY&                  thePoint,
313     const Handle(HYDROData_Zone)& theZone ) const;
314
315   HYDRODATA_EXPORT void SetAssignmentMode( AssignmentMode theMode );
316   HYDRODATA_EXPORT AssignmentMode GetAssignmentMode() const;
317
318   HYDRODATA_EXPORT void ClearRules( const bool theIsSetToUpdate = true );
319   HYDRODATA_EXPORT void AddRule( const Handle(HYDROData_Object)&    theObject1,
320                                  HYDROData_PriorityType             thePriority,
321                                  const Handle(HYDROData_Object)&    theObject2,
322                                  HYDROData_Zone::MergeAltitudesType theMergeType );
323   HYDRODATA_EXPORT bool GetRule( int theIndex, 
324                                  Handle(HYDROData_Object)&           theObject1,
325                                  HYDROData_PriorityType&             thePriority,
326                                  Handle(HYDROData_Object)&           theObject2,
327                                  HYDROData_Zone::MergeAltitudesType& theMergeType ) const;
328
329   HYDRODATA_EXPORT QString DumpRules() const;
330
331   HYDRODATA_EXPORT HYDROData_Warning GetLastWarning() const;
332
333 private:
334
335   /**
336    * Add new one region for calculation case.
337    * The new region is added into the list of reference regions.
338    */
339   Handle(HYDROData_Region) addNewRegion( const Handle(HYDROData_Document)& theDoc,
340                                          const QString& thePrefixOrName,
341                                          bool isPrefix = true );
342
343   /**
344    * Add new one splitted edges group for calculation case.
345    */
346   Handle(HYDROData_SplittedShapesGroup) addNewSplittedGroup( const QString& theName );
347
348   /**
349    * Exports the given faces as shell and the given groups to GEOM module.
350    * \param theGeomEngine GEOM module engine
351    * \param theStudy SALOMEDS study, is used for publishing of GEOM objects
352    * \param theFaces the list of faces to make shell 
353    * \param theSplittedGroups the list of groups
354    * \return true in case of success
355    */
356   bool Export( GEOM::GEOM_Gen_var                            theGeomEngine,
357                SALOMEDS::Study_ptr                           theStudy,
358                const TopTools_ListOfShape&                   theFaces,
359                const HYDROData_ShapesGroup::SeqOfGroupsDefs& theGroupsDefs,
360                QString& theGeomObjEntry ) const;
361
362   /**
363    * Publish the given shape in GEOM as a GEOM object.
364    * \param theGeomEngine GEOM module engine
365    * \param theStudy SALOMEDS study, used for publishing of the shape
366    * \param theShape the shape to publish as a GEOM object
367    * \param theName the name of the published object
368    * \return the published GEOM object
369    */
370   GEOM::GEOM_Object_ptr publishShapeInGEOM( GEOM::GEOM_Gen_var  theGeomEngine,
371                                             SALOMEDS::Study_ptr theStudy,
372                                             const TopoDS_Shape& theShape, 
373                                             const QString&      theName,
374                                             QString& theGeomObjEntry ) const;
375
376   void CreateRegionsDef( const Handle(HYDROData_Document)& theDoc,
377                          const HYDROData_SplitToZonesTool::SplitDataList& theZones );
378   void CreateRegionsAuto( const Handle(HYDROData_Document)& theDoc,
379                           const HYDROData_SplitToZonesTool::SplitDataList& theZones );
380
381   void CreateEdgeGroupsDef( const Handle(HYDROData_Document)& theDoc,
382                             const HYDROData_SplitToZonesTool::SplitDataList& theEdges );
383
384   void DumpRulesToPython( const QString& theCalcCaseName, QStringList& theScript ) const;
385
386   void SetWarning( HYDROData_WarningType theType = WARN_OK, const QString& theData = "" );
387
388 protected:
389   friend class HYDROData_Iterator;
390
391   /**
392    * Creates new object in the internal data structure. Use higher level objects 
393    * to create objects with real content.
394    */
395   HYDRODATA_EXPORT HYDROData_CalculationCase();
396
397   /**
398    * Destructs properties of the object and object itself, removes it from the document.
399    */
400   HYDRODATA_EXPORT ~HYDROData_CalculationCase();
401
402   void DumpSampleMeshing( QStringList& theScript,
403                           const QString& theStudyName,
404                           const QString& theGeomShapeName,
405                           const QString& theMeshName ) const;
406
407 private:
408   HYDROData_Warning myLastWarning;
409 };
410
411 #endif