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