1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // Partitioning/decimation module for the SALOME v3.2 platform
25 * \brief C++ implementation of the CORBA interface of the MULTIPR module.
27 * \author Olivier LE ROUX - CS, Virtual Reality Dpt
33 //*****************************************************************************
35 //*****************************************************************************
37 #ifndef __MULTIPR_IMPLEMENTATION_CORBA__
38 #define __MULTIPR_IMPLEMENTATION_CORBA__
40 #include <SALOMEconfig.h>
41 #include CORBA_SERVER_HEADER(MULTIPR)
42 #include "SALOME_Component_i.hxx"
43 #include "Utils_CorbaException.hxx"
45 #include "SALOME_GenericObj_i.hh"
47 #include "MULTIPR_Obj.hxx"
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 //*****************************************************************************
62 public POA_MULTIPR_ORB::MULTIPR_Obj,
63 public virtual SALOME::GenericObj_i
70 * Associate a MED file (sequential or distributed) with this object.
71 * \param pMEDFilename MED file to be associated with this object.
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);
82 virtual ~MULTIPR_Obj_i();
84 //---------------------------------------------------------------------
85 // Basic accessors/mutators
86 //--------------------------------------------------------------------
92 throw (SALOME::SALOME_Exception);
95 * Returns true iff this obj represents a valid sequential MED file.
96 * \return true iff this obj represents a valid sequential MED file.
98 CORBA::Boolean isValidSequentialMEDFile()
99 throw (SALOME::SALOME_Exception);
102 * Returns true iff this obj represents a valid distributed MED file.
103 * \return true iff this obj represents a valid distributed MED file.
105 CORBA::Boolean isValidDistributedMEDFile()
106 throw (SALOME::SALOME_Exception);
109 * Returns the name of the associated MED file.
110 * \return the name of the associated MED file.
113 throw (SALOME::SALOME_Exception);
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).
119 char* getSeqFilename()
120 throw (SALOME::SALOME_Exception);
123 * Defines the mesh to be processed.
124 * \param pMeshName name of the mesh to be partitionned.
126 void setMesh(const char* pMeshName)
127 throw (SALOME::SALOME_Exception);
130 * Returns a name of the mesh to be processed.
131 * \return a name of the mesh to be processed.
133 std::string getMeshName() const
134 throw (SALOME::SALOME_Exception);
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].
141 void setBoxing(CORBA::Long pBoxing)
142 throw (SALOME::SALOME_Exception);
145 * Returns currently set boxing parameter for decimation.
146 * \return currently set boxing parameter for decimation.
148 int getBoxing() const { return mBoxing; }
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.
155 MULTIPR_ORB::string_array* getMeshes()
156 throw (SALOME::SALOME_Exception);
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.
164 MULTIPR_ORB::string_array* getFields(const char* pPartList)
165 throw (SALOME::SALOME_Exception);
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.
174 CORBA::Long getTimeStamps(const char* pPartList, const char* pFieldName)
175 throw (SALOME::SALOME_Exception);
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.
184 void getFieldMinMax(const char* pPartName, const char* pFieldName, CORBA::Float& pMin, CORBA::Float& pMax)
185 throw (SALOME::SALOME_Exception);
188 * Returns the name of all partitions.
189 * Assumes this object encapsulates a distributed MED file.
190 * \return the name of all partitions.
192 MULTIPR_ORB::string_array* getParts()
193 throw (SALOME::SALOME_Exception);
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.
201 char* getPartInfo(const char* pPartName)
202 throw (SALOME::SALOME_Exception);
204 //---------------------------------------------------------------------
206 //---------------------------------------------------------------------
209 * Creates a distributed MED file (v2.3) by extracting all the groups from the current mesh of the current MED sequential MED file.
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.
217 MULTIPR_ORB::string_array* partitionneDomaine()
218 throw (SALOME::SALOME_Exception);
221 * Creates a distributed MED file (V2.3) by splitting a group of a MED file previously created by partitionneDomaine.
223 * - the file is a distributed MED file, previously created by partitionneDomaine()
224 * (=> each part only contain 1 mesh, TETRA10 elements only)
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.
231 MULTIPR_ORB::string_array* partitionneGroupe(
232 const char* pPartName,
233 CORBA::Long pNbParts,
234 CORBA::Long pPartitionner)
235 throw (SALOME::SALOME_Exception);
238 * Creates 3 resolutions of the given part of a distributed MED file (V2.3).
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.
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);
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.
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);
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).
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);
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.
297 void removeParts(const char* pPrefixPartName)
298 throw (SALOME::SALOME_Exception);
301 * Get mesh statistics.
302 * \return Mesh statistics !
304 char* getMEDInfo(const char* pPartName)
305 throw (SALOME::SALOME_Exception);
307 //---------------------------------------------------------------------
309 //---------------------------------------------------------------------
312 * Saves the associated MED file if necessary.
313 * \param pPath path where to save the file.
315 void save(const char* pPath)
316 throw (SALOME::SALOME_Exception);
319 * Check save progress.
320 * \return current save progress in percents.
322 CORBA::Long getSaveProgress();
325 * Reset save progress to zero.
327 void resetSaveProgress();
329 //---------------------------------------------------------------------
330 // Persistence and Dump Python
331 //---------------------------------------------------------------------
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.
338 void savePersistent (const char* pPath)
339 throw (SALOME::SALOME_Exception);
344 //void setEngine (MULTIPR_ORB::MULTIPR_Gen_ptr theEngine);
345 void setEngine (MULTIPR_Gen_i* theEngine);
350 * The associated MULTIPR object.
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.
364 MULTIPR_Gen_i* _engine;
367 * Is restored MED file (Used by Persistence to remove temporary files).
373 //*****************************************************************************
374 // Class MULTIPR_Gen_i
375 // C++ implementation of the MULTIPR_Gen CORBA interface
376 //*****************************************************************************
378 class MULTIPR_Gen_i :
379 public POA_MULTIPR_ORB::MULTIPR_Gen,
380 public Engines_Component_i
387 PortableServer::POA_ptr poa,
388 PortableServer::ObjectId* contId,
389 const char* instanceName,
390 const char* interfaceName);
392 virtual ~MULTIPR_Gen_i();
395 throw (SALOME::SALOME_Exception);
397 void partitionneDomaine(
398 const char* medFilename,
399 const char* meshName)
400 throw (SALOME::SALOME_Exception);
402 void partitionneGroupe(
403 const char* medFilename,
404 const char* partName,
406 CORBA::Long partitionner)
407 throw (SALOME::SALOME_Exception);
409 void decimePartition(
410 const char* medFilename,
411 const char* partName,
412 const char* fieldName,
414 const char* filterName,
415 const char* filterParams)
416 throw (SALOME::SALOME_Exception);
418 MULTIPR_ORB::MULTIPR_Obj_ptr getObject(const char* medFilename)
419 throw (SALOME::SALOME_Exception);
421 // ****************************************************
422 // Set/Get current study for Persistence and Dump Python
423 // ****************************************************
426 void SetCurrentStudy (SALOMEDS::Study_ptr theStudy);
428 SALOMEDS::Study_ptr GetCurrentStudy();
430 // Mark current study as modified, if theObj is published in it
431 void ObjModified (MULTIPR_ORB::MULTIPR_Obj_ptr theObj);
433 // ****************************************************
434 // Interface inherited methods (from SALOMEDS::Driver)
435 // ****************************************************
438 SALOMEDS::TMPFile* Save (SALOMEDS::SComponent_ptr theComponent,
442 bool Load (SALOMEDS::SComponent_ptr theComponent,
443 const SALOMEDS::TMPFile& theStream,
447 // Save SMESH data in ASCII format
448 SALOMEDS::TMPFile* SaveASCII (SALOMEDS::SComponent_ptr theComponent,
451 // Load SMESH data in ASCII format
452 bool LoadASCII (SALOMEDS::SComponent_ptr theComponent,
453 const SALOMEDS::TMPFile& theStream,
457 // Clears study-connected data when it is closed
458 void Close (SALOMEDS::SComponent_ptr theComponent);
460 // Get component data type
461 char* ComponentDataType();
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);
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,
481 throw (SALOME::SALOME_Exception);
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)
494 SALOMEDS::SObject_var aResultSO;
495 return aResultSO._retn();
502 virtual Engines::TMPFile* DumpPython (CORBA::Object_ptr theStudy,
503 CORBA::Boolean isPublished,
504 CORBA::Boolean& isValidScript);
506 void AddToPythonScript (int theStudyID, std::string theString);
509 std::string DumpPython_impl (int theStudyID,
512 std::string theSavedTrace);
514 std::string GetNewPythonLines (int theStudyID);
515 void CleanPythonTrace (int theStudyID);
516 void SavePython (SALOMEDS::Study_ptr theStudy);
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;
528 extern "C" PortableServer::ObjectId* MULTIPREngine_factory(
530 PortableServer::POA_ptr poa,
531 PortableServer::ObjectId * contId,
532 const char* instanceName,
533 const char* interfaceName);
535 #endif // __MULTIPR_IMPLEMENTATION_CORBA__