]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_i.hxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/multipr.git] / src / MULTIPR / MULTIPR_i.hxx
1 // Project MULTIPR, IOLS WP1.2.1 - EDF/CS
2 // Partitioning/decimation module for the SALOME v3.2 platform
3
4 /**
5  * \file    MULTIPR_i.hxx
6  *
7  * \brief   C++ implementation of the CORBA interface of the MULTIPR module.
8  *
9  * \author  Olivier LE ROUX - CS, Virtual Reality Dpt
10  *
11  * \date    01/2007
12  */
13
14
15 //*****************************************************************************
16 // Includes section
17 //*****************************************************************************
18
19 #ifndef __MULTIPR_IMPLEMENTATION_CORBA__
20 #define __MULTIPR_IMPLEMENTATION_CORBA__
21
22 #include <SALOMEconfig.h>
23 #include CORBA_SERVER_HEADER(MULTIPR)
24 #include "SALOME_Component_i.hxx"
25 #include "Utils_CorbaException.hxx"
26
27 #include "SALOME_GenericObj_i.hh"
28
29 #include "MULTIPR_Obj.hxx"
30
31 #include <map>
32 #include <vector>
33 #include <string>
34
35 class MULTIPR_Gen_i;
36
37 //*****************************************************************************
38 // Class MULTIPR_Obj_i
39 // C++ implementation of the MULTIPR_Obj CORBA interface
40 // This class is a wrapper to encapsulate MULTIPR_Obj
41 //*****************************************************************************
42
43 class MULTIPR_Obj_i :
44     public POA_MULTIPR_ORB::MULTIPR_Obj,
45     public virtual SALOME::GenericObj_i
46 {
47
48 public:
49
50     /**
51      * Constructor.
52      * Associate a MED file (sequential or distributed) with this object.
53      * \param  pMEDFilename MED file to be associated with this object.
54      */
55     MULTIPR_Obj_i (PortableServer::POA_ptr thePOA,
56                    const char* pMEDFilename,
57                    bool isPersistence = false,
58                    bool isMultifile   = false)
59         throw (SALOME::SALOME_Exception);
60
61     /**
62      * Destructor.
63      */
64     virtual ~MULTIPR_Obj_i();
65
66     //---------------------------------------------------------------------
67     // Basic accessors/mutators
68     //--------------------------------------------------------------------
69
70     /**
71      * Reset the object.
72      */
73     void    reset()
74         throw (SALOME::SALOME_Exception);
75
76     /**
77      * Returns true iff this obj represents a valid sequential MED file.
78      * \return true iff this obj represents a valid sequential MED file.
79      */
80     CORBA::Boolean isValidSequentialMEDFile()
81         throw (SALOME::SALOME_Exception);
82
83     /**
84      * Returns true iff this obj represents a valid distributed MED file.
85      * \return true iff this obj represents a valid distributed  MED file.
86      */
87     CORBA::Boolean isValidDistributedMEDFile()
88         throw (SALOME::SALOME_Exception);
89
90     /**
91      * Returns the name of the associated MED file.
92      * \return the name of the associated MED file.
93      */
94     char* getFilename()
95         throw (SALOME::SALOME_Exception);
96
97     /**
98      * Returns the name of the associated sequential MED file (for a distributed MED file).
99      * \return the name of the associated sequential MED file (for a distributed MED file).
100      */
101     char* getSeqFilename()
102         throw (SALOME::SALOME_Exception);
103
104     /**
105      * Defines the mesh to be processed.
106      * \param  pMeshName name of the mesh to be partitionned.
107      */
108     void setMesh(const char* pMeshName)
109         throw (SALOME::SALOME_Exception);
110
111     /**
112      * Returns a name of the mesh to be processed.
113      * \return a name of the mesh to be processed.
114      */
115     std::string getMeshName() const
116         throw (SALOME::SALOME_Exception);
117
118     /**
119      * Sets boxing parameters for decimation (100 by default).
120      * \param  pBoxing number of cells along each axis of the grid
121      * (= acceleration structure) ; should be in [1..200].
122      */
123     void setBoxing(CORBA::Long pBoxing)
124         throw (SALOME::SALOME_Exception);
125
126     /**
127      * Returns currently set boxing parameter for decimation.
128      * \return currently set boxing parameter for decimation.
129      */
130     int getBoxing() const { return mBoxing; }
131
132     /**
133      * Returns the list of meshes contained in the sequential MED file.
134      * Assumes this object encapsulates a sequential MED file.
135      * \return the list of meshes contained in the sequential MED file.
136      */
137     MULTIPR_ORB::string_array* getMeshes()
138         throw (SALOME::SALOME_Exception);
139
140     /**
141      * Returns the list of fields contained in the sequential MED file.
142      * Assumes this object encapsulates a sequential MED file.
143      * \param pPartList The list of parts to get the fields from (separator is '|').
144      * \return the list of fields contained in the sequential MED file.
145      */
146     MULTIPR_ORB::string_array* getFields(const char* pPartList)
147         throw (SALOME::SALOME_Exception);
148
149     /**
150      * Returns the number of timestamps for a given field.
151      * Assumes this object encapsulates a sequential MED file.
152      * \param pPartList The list of parts to get the fields from (separator is '|').
153      * \param  pFieldName name of any field.
154      * \return the number of timestamps for a given field; 0 if field not found.
155      */
156     CORBA::Long getTimeStamps(const char* pPartList, const char* pFieldName)
157         throw (SALOME::SALOME_Exception);
158
159     /**
160      * Get the minimum and maximum value of a part's field.
161      * \param pPartName The name of the part.
162      * \param pFieldName The name of the field.
163      * \param pMin The mininum value to fill.
164      * \param pMax The maxinum value to fill.
165      */
166     void getFieldMinMax(const char* pPartName, const char* pFieldName, CORBA::Float& pMin, CORBA::Float& pMax)
167        throw (SALOME::SALOME_Exception);
168
169     /**
170      * Returns the name of all partitions.
171      * Assumes this object encapsulates a distributed MED file.
172      * \return the name of all partitions.
173      */
174     MULTIPR_ORB::string_array* getParts()
175         throw (SALOME::SALOME_Exception);
176
177     /**
178      * Returns all information abour a part.
179      * Assumes this object encapsulates a distributed MED file.
180      * \param  pPartName name of the part.
181      * \return information about a part.
182      */
183     char* getPartInfo(const char* pPartName)
184         throw (SALOME::SALOME_Exception);
185
186     //---------------------------------------------------------------------
187     // Algorithms
188     //---------------------------------------------------------------------
189
190     /**
191      * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file.
192      *         Assumes:
193      *         - the file is in MED format and can be read using MED file v2.3.
194      *         - the file is sequential (not a distributed MED).
195      *         - the file only contains TETRA10 elements (dimension of space and mesh is 3).
196      *         - the file have no profil.
197      * \return the name of each part.
198      */
199     MULTIPR_ORB::string_array* partitionneDomaine()
200         throw (SALOME::SALOME_Exception);
201
202     /**
203      * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine.
204      *         Assumes:
205      *         - the file is a distributed MED file, previously created by partitionneDomaine()
206      *           (=> each part only contain 1 mesh, TETRA10 elements only)
207      *         - nbPart > 1
208      * \param  pPartName     name of the part to be splitted.
209      * \param  pNbParts      number of parts; must be > 1.
210      * \param  pPartitionner use value 0=MULTIPR_METIS for Metis or 1=MULTIPR_SCOTCH for Scotch.
211      * \return the name of each part.
212      */
213     MULTIPR_ORB::string_array* partitionneGroupe(
214         const char* pPartName,
215         CORBA::Long pNbParts,
216         CORBA::Long pPartitionner)
217         throw (SALOME::SALOME_Exception);
218
219     /**
220      * Creates 3 resolutions of the given part of a distributed MED file (V2.3).
221      *         Assumes:
222      *         - the file is a distributed MED file, previously created by partitionneDomaine() or partitionneGrain()
223      *           (=> each part only contain 1 mesh, TETRA10 elements only)
224      * \param  pPartName    name of the part to be decimated.
225      * \param  pFieldName   name of the field used for decimation.
226      * \param  pFieldIt     iteration (time step) of the field.
227      * \param  pFilterName  name of the filter to be used.
228      * \param  pTmed        threshold used for medium resolution.
229      * \param  pTlow        threshold used for low resolution; tmed must be less than tlow
230      * \param  pTadius      radius used to determine the neighbourhood.
231      * \return the name of each part.
232      */
233     MULTIPR_ORB::string_array* decimePartition(
234         const char*   pPartName,
235         const char*   pFieldName,
236         CORBA::Long   pFieldIt,
237         const char*   pFilterName,
238         const char*   pFilterParams)
239         throw (SALOME::SALOME_Exception);
240
241     /**
242      * Works exactly like the above method, but returns not a list
243      * of all parts, but a list of empty obtained resolutions.
244      * \return the list of empty resolutions.
245      */
246   /*
247     MULTIPR_ORB::string_array* decimatePart(
248         const char*   pPartName,
249         const char*   pFieldName,
250         CORBA::Long   pFieldIt,
251         const char*   pFilterName,
252         const char*   pFilterParams)
253         throw (SALOME::SALOME_Exception);
254   */
255
256     /**
257      * Returns useful information to configure decimation parameters.
258      * Depends on part, field and filter: generic operation.
259      * \param  pPartName     name of the part.
260      * \param  pFieldName    name of the field used for decimation.
261      * \param  pFieldIt      iteration (time step) of the field.
262      * \param  pFilterName   name of the filter to be used.
263      * \param  pFilterParams params to be used with the filter (depends on filter; this string will be parsed).
264      */
265     char* evalDecimationParams(
266         const char* pPartName,
267         const char* pFieldName,
268         CORBA::Long pFieldIt,
269         const char* pFilterName,
270         const char* pFilterParams)
271         throw (SALOME::SALOME_Exception);
272
273     /*!
274      * Removes all the parts starting with "pPrefixPartName" from the distributed MED file.
275      * Example: if pPrefixPartName="PART_4" => remove "PART_4" and all sub-parts "PART_4_*", but not "PART41".
276      * Assume this object encapsulates a distributed MED file.
277      * \param  pPrefixPartName name of the part.
278      */
279     void removeParts(const char* pPrefixPartName)
280         throw (SALOME::SALOME_Exception);
281
282     /**
283      * Get mesh statistics.
284      * \return Mesh statistics !
285      */
286     char* getMEDInfo(const char* pPartName)
287         throw (SALOME::SALOME_Exception);
288
289     //---------------------------------------------------------------------
290     // I/O
291     //---------------------------------------------------------------------
292
293     /**
294      * Saves the associated MED file if necessary.
295      * \param  pPath path where to save the file.
296      */
297     void save(const char* pPath)
298         throw (SALOME::SALOME_Exception);
299
300     /**
301      * Check save progress.
302      * \return current save progress in percents.
303      */
304     CORBA::Long getSaveProgress();
305
306     /**
307      * Reset save progress to zero.
308      */
309     void resetSaveProgress();
310
311     //---------------------------------------------------------------------
312     // Persistence and Dump Python
313     //---------------------------------------------------------------------
314
315     /**
316      * Saves the associated MED file to the given location.
317      * \note To be used only for persistence.
318      * \param pPath path where to save the file.
319      */
320     void savePersistent (const char* pPath)
321       throw (SALOME::SALOME_Exception);
322
323     /**
324      * Set Engine.
325      */
326     //void setEngine (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine);
327     void setEngine (MULTIPR_Gen_i* theEngine);
328
329 private:
330
331     /**
332      * The associated MULTIPR object.
333      */
334     multipr::Obj* mObj;
335
336     /**
337      * Boxing paremeter: number of cells along each axis.
338      * E.g. if mBoxing=10 then total number of cells = 10*10*10 = 1000.
339      * By default, mBoxing=100.
340      */
341     int mBoxing;
342
343     /**
344      * Engine.
345      */
346     MULTIPR_Gen_i* _engine;
347
348     /**
349      * Is restored MED file (Used by Persistence to remove temporary files).
350      */
351     bool mIsTmp;
352 };
353
354
355 //*****************************************************************************
356 // Class MULTIPR_Gen_i
357 // C++ implementation of the MULTIPR_Gen CORBA interface
358 //*****************************************************************************
359
360 class MULTIPR_Gen_i :
361     public POA_MULTIPR_ORB::MULTIPR_Gen,
362     public Engines_Component_i
363 {
364
365 public:
366
367     MULTIPR_Gen_i(
368         CORBA::ORB_ptr orb,
369         PortableServer::POA_ptr poa,
370         PortableServer::ObjectId* contId,
371         const char* instanceName,
372         const char* interfaceName);
373
374     virtual ~MULTIPR_Gen_i();
375
376     char* getVersion()
377         throw (SALOME::SALOME_Exception);
378
379     void partitionneDomaine(
380         const char* medFilename,
381         const char* meshName)
382         throw (SALOME::SALOME_Exception);
383
384     void partitionneGroupe(
385         const char* medFilename,
386         const char* partName,
387         CORBA::Long nbParts,
388         CORBA::Long partitionner)
389         throw (SALOME::SALOME_Exception);
390
391     void decimePartition(
392         const char*   medFilename,
393         const char*   partName,
394         const char*   fieldName,
395         CORBA::Long   fieldIt,
396         const char*   filterName,
397         const char*   filterParams)
398         throw (SALOME::SALOME_Exception);
399
400     MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename)
401         throw (SALOME::SALOME_Exception);
402
403   // ****************************************************
404   // Set/Get current study for Persistence and Dump Python
405   // ****************************************************
406
407   // Set current study
408   void SetCurrentStudy (SALOMEDS::Study_ptr theStudy);
409   // Get current study
410   SALOMEDS::Study_ptr GetCurrentStudy();
411
412   // Mark current study as modified, if theObj is published in it
413   void ObjModified (MULTIPR_ORB::MULTIPR_Obj_ptr theObj);
414
415   // ****************************************************
416   // Interface inherited methods (from SALOMEDS::Driver)
417   // ****************************************************
418
419   // Save SMESH data
420   SALOMEDS::TMPFile* Save (SALOMEDS::SComponent_ptr theComponent,
421                            const char*              theURL,
422                            bool                     isMultiFile);
423   // Load SMESH data
424   bool Load (SALOMEDS::SComponent_ptr theComponent,
425              const SALOMEDS::TMPFile& theStream,
426              const char*              theURL,
427              bool                     isMultiFile);
428
429   // Save SMESH data in ASCII format
430   SALOMEDS::TMPFile* SaveASCII (SALOMEDS::SComponent_ptr theComponent,
431                                 const char*              theURL,
432                                 bool                     isMultiFile);
433   // Load SMESH data in ASCII format
434   bool LoadASCII (SALOMEDS::SComponent_ptr theComponent,
435                   const SALOMEDS::TMPFile& theStream,
436                   const char*              theURL,
437                   bool                     isMultiFile);
438
439   // Clears study-connected data when it is closed
440   void Close (SALOMEDS::SComponent_ptr theComponent);
441
442   // Get component data type
443   char* ComponentDataType();
444
445   // Transform data from transient form to persistent
446   char* IORToLocalPersistentID (SALOMEDS::SObject_ptr theSObject,
447                                 const char*           IORString,
448                                 CORBA::Boolean        isMultiFile,
449                                 CORBA::Boolean        isASCII);
450   // Transform data from persistent form to transient
451   char* LocalPersistentIDToIOR (SALOMEDS::SObject_ptr theSObject,
452                                 const char*           aLocalPersistentID,
453                                 CORBA::Boolean        isMultiFile,
454                                 CORBA::Boolean        isASCII);
455
456   // Returns true if object can be published in the study
457   bool CanPublishInStudy (CORBA::Object_ptr theIOR);
458   // Publish object in the study
459   SALOMEDS::SObject_ptr PublishInStudy (SALOMEDS::Study_ptr   theStudy,
460                                         SALOMEDS::SObject_ptr theSObject,
461                                         CORBA::Object_ptr     theObject,
462                                         const char*           theName)
463     throw (SALOME::SALOME_Exception);
464
465   // Copy-paste methods - returns true if object can be copied to the clipboard
466   CORBA::Boolean CanCopy (SALOMEDS::SObject_ptr theObject) { return false; }
467   // Copy-paste methods - copy object to the clipboard
468   SALOMEDS::TMPFile* CopyFrom (SALOMEDS::SObject_ptr theObject, CORBA::Long& theObjectID) { return false; }
469   // Copy-paste methods - returns true if object can be pasted from the clipboard
470   CORBA::Boolean CanPaste (const char* theComponentName, CORBA::Long theObjectID) { return false; }
471   // Copy-paste methods - paste object from the clipboard
472   SALOMEDS::SObject_ptr PasteInto (const SALOMEDS::TMPFile& theStream,
473                                    CORBA::Long              theObjectID,
474                                    SALOMEDS::SObject_ptr    theObject)
475   {
476     SALOMEDS::SObject_var aResultSO;
477     return aResultSO._retn();
478   }
479
480   // ============
481   // Dump python
482   // ============
483
484   virtual Engines::TMPFile* DumpPython (CORBA::Object_ptr theStudy,
485                                         CORBA::Boolean isPublished,
486                                         CORBA::Boolean& isValidScript);
487
488   void AddToPythonScript (int theStudyID, std::string theString);
489
490 private:
491   std::string DumpPython_impl (int theStudyID,
492                                bool isPublished,
493                                bool& aValidScript,
494                                std::string theSavedTrace);
495
496   std::string GetNewPythonLines (int theStudyID);
497   void CleanPythonTrace (int theStudyID);
498   void SavePython (SALOMEDS::Study_ptr theStudy);
499
500 private:
501   // Current study
502   SALOMEDS::Study_var myCurrentStudy;
503   // Dump Python: trace of API methods calls
504   std::map < int, std::vector <std::string> > myPythonScripts;
505   // Tmp directory. Used by Persistence.
506   std::string myTmpDir;
507 };
508
509
510 extern "C" PortableServer::ObjectId* MULTIPREngine_factory(
511     CORBA::ORB_ptr orb,
512     PortableServer::POA_ptr poa,
513     PortableServer::ObjectId * contId,
514     const char* instanceName,
515     const char* interfaceName);
516
517 #endif // __MULTIPR_IMPLEMENTATION_CORBA__
518
519 // EOF