]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_i.cxx
Salome HOME
a8eff220bcbeb9ea7cf6df0d832abe0fa0d4d710
[modules/multipr.git] / src / MULTIPR / MULTIPR_i.cxx
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.cxx
6  *
7  * \brief   see MULTIPR_i.hxx
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 using namespace std;
20
21 #include "MULTIPR_i.hxx"
22 #include "utilities.h"
23
24 #include <string>
25
26 #include "MULTIPR_API.hxx"
27 #include "MULTIPR_Exceptions.hxx"
28
29
30 //*****************************************************************************
31 // Class MULTIPR_Gen_i implementation
32 //*****************************************************************************
33
34 MULTIPR_Gen_i::MULTIPR_Gen_i(
35         CORBA::ORB_ptr orb,
36         PortableServer::POA_ptr poa,
37         PortableServer::ObjectId* contId, 
38         const char* instanceName, 
39         const char* interfaceName) :
40         Engines_Component_i(orb, poa, contId, instanceName, interfaceName)
41 {
42         MESSAGE("activate object");
43         _thisObj = this ;
44         _id = _poa->activate_object(_thisObj);
45 }
46
47
48 MULTIPR_Gen_i::~MULTIPR_Gen_i()
49 {
50 }
51
52
53 //-----------------------------------------------------------------------------
54 // High level API
55 //-----------------------------------------------------------------------------
56
57 char* MULTIPR_Gen_i::getVersion()
58         throw (SALOME::SALOME_Exception)
59 {
60         return CORBA::string_dup(multipr::getVersion());
61 }
62
63
64 void MULTIPR_Gen_i::partitionneDomaine(
65         const char* medFilename, 
66         const char* meshName)
67         throw (SALOME::SALOME_Exception)
68 {
69         try
70         {
71                 multipr::partitionneDomaine(medFilename, meshName);
72         }
73         catch (multipr::RuntimeException& e)
74         {
75                 e.dump(cout);
76                 THROW_SALOME_CORBA_EXCEPTION("partitionneDomaine() failed", SALOME::INTERNAL_ERROR);
77         }
78 }
79
80
81 void MULTIPR_Gen_i::partitionneGrain(
82         const char* medFilename, 
83         const char* partName, 
84         CORBA::Long nbParts, 
85         CORBA::Long partitionner)
86         throw (SALOME::SALOME_Exception)
87 {
88         try
89         {
90                 multipr::partitionneGrain(
91                         medFilename,
92                         partName,
93                         nbParts,
94                         partitionner);
95         }
96         catch (multipr::RuntimeException& e)
97         {
98                 e.dump(cout);
99                 THROW_SALOME_CORBA_EXCEPTION("partitionneGrain() failed", SALOME::INTERNAL_ERROR);
100         }
101 }
102
103
104 void MULTIPR_Gen_i::decimePartition(
105         const char*   medFilename, 
106         const char*   partName, 
107         const char*   fieldName,
108         CORBA::Long   fieldIt,
109         const char*   filterName,
110         CORBA::Double tmed,
111         CORBA::Double tlow,
112         CORBA::Double radius,
113         CORBA::Long   boxing)
114         throw (SALOME::SALOME_Exception)
115 {
116         /*
117         // debug
118         cout << "File  : " << medFilename << endl;
119         cout << "Part  : " << partName    << endl;
120         cout << "Field : " << fieldName   << endl;
121         cout << "It    : " << fieldIt     << endl;
122         cout << "Filter: " << filterName  << endl;
123         cout << "Med   : " << tmed        << endl;
124         cout << "Low   : " << tlow        << endl;
125         cout << "Rad   : " << radius      << endl;
126         cout << "Box   : " << boxing      << endl;
127         cout << endl;
128         */
129         
130         try
131         {
132                 multipr::decimePartition(
133                         medFilename, 
134                         partName, 
135                         fieldName,
136                         fieldIt,
137                         filterName,
138                         tmed,
139                         tlow,
140                         radius,
141                         boxing);
142         }
143         catch (multipr::RuntimeException& e)
144         {
145                 e.dump(cout);
146                 THROW_SALOME_CORBA_EXCEPTION("decimePartition() failed", SALOME::INTERNAL_ERROR);
147         }
148 }
149
150
151 //-----------------------------------------------------------------------------
152 // Low level API
153 //-----------------------------------------------------------------------------
154
155 MULTIPR_ORB::MULTIPR_Obj_ptr MULTIPR_Gen_i::getObject(const char* medFilename)
156         throw (SALOME::SALOME_Exception)
157 {
158     MULTIPR_Obj_i* obj = new MULTIPR_Obj_i(medFilename);
159         return obj->POA_MULTIPR_ORB::MULTIPR_Obj::_this();
160 }
161
162
163 MULTIPR_Obj_i::MULTIPR_Obj_i(const char* medFilename)
164         throw (SALOME::SALOME_Exception)
165 {
166         mObj    = new multipr::Obj();
167         mBoxing = 100;
168         
169         try
170         {
171                 cout << "Load " << medFilename << endl;
172                 mObj->create(medFilename);
173                 cout << endl;
174         }
175         catch (multipr::RuntimeException& e)
176         {
177                 delete mObj;
178                 mObj = NULL;
179                 e.dump(cout);
180                 THROW_SALOME_CORBA_EXCEPTION("Unable to create object", SALOME::INTERNAL_ERROR);
181         }
182 }
183
184
185 MULTIPR_Obj_i::~MULTIPR_Obj_i()
186 {
187         if (mObj != NULL)
188         {
189                 cout << "MULTIPR: Destructor: remove mObj" << endl;
190                 delete mObj;
191                 mObj = NULL;
192         }
193 }
194
195
196 CORBA::Boolean MULTIPR_Obj_i::isValidSequentialMEDFile()
197                 throw (SALOME::SALOME_Exception)
198 {
199         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
200         
201         return mObj->isValidSequentialMEDFile();
202 }
203
204
205 CORBA::Boolean MULTIPR_Obj_i::isValidDistributedMEDFile()
206         throw (SALOME::SALOME_Exception)
207 {
208         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
209         
210         return mObj->isValidDistributedMEDFile();
211 }
212
213
214 char* MULTIPR_Obj_i::getFilename()
215                 throw (SALOME::SALOME_Exception)
216 {
217         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
218         
219         return CORBA::string_dup(mObj->getMEDFilename().c_str());
220 }
221
222
223 void MULTIPR_Obj_i::setMesh(const char* meshName)
224                 throw (SALOME::SALOME_Exception)
225 {
226         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
227         
228         try
229         {
230                 mObj->setMesh(meshName);
231                 
232                 cout << "Set mesh OK" << endl << endl;
233         }
234         catch (multipr::RuntimeException& e)
235         {
236                 e.dump(cout);
237                 THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR);
238         }
239 }
240
241
242 void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing)
243         throw (SALOME::SALOME_Exception)
244 {
245         if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR);
246         if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR);
247         
248         mBoxing = pBoxing;
249 }
250
251
252 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getMeshes() 
253         throw (SALOME::SALOME_Exception)
254 {
255         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
256         
257         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
258         
259         try
260         {
261                 std::vector<std::string> listMeshes = mObj->getMeshes();
262                 mySeq->length(listMeshes.size());
263                 
264                 for (int i = 0 ; i < listMeshes.size() ; i++)
265         {
266                 mySeq[i] = CORBA::string_dup(listMeshes[i].c_str());
267         }
268         }
269         catch (multipr::RuntimeException& e)
270         {
271                 e.dump(cout);
272                 THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR);
273         }
274         
275     return mySeq._retn();
276 }
277
278
279 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getFields() 
280         throw (SALOME::SALOME_Exception)
281 {
282         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
283         
284         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
285         
286         try
287         {
288                 std::vector<std::string> listFields = mObj->getFields();
289                 mySeq->length(listFields.size());
290                 
291                 for (int i = 0 ; i < listFields.size() ; i++)
292         {
293                 mySeq[i] = CORBA::string_dup(listFields[i].c_str());
294         }
295         }
296         catch (multipr::RuntimeException& e)
297         {
298                 e.dump(cout);
299                 THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR);
300         }
301         
302     return mySeq._retn();
303 }
304
305
306 CORBA::Long MULTIPR_Obj_i::getTimeStamps(const char* fieldName)
307         throw (SALOME::SALOME_Exception)
308 {
309         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
310         
311         try
312         {
313                 return mObj->getTimeStamps(fieldName);
314         }
315         catch (multipr::RuntimeException& e)
316         {
317                 e.dump(cout);
318                 THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR);
319         }
320 }
321
322
323 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts()
324         throw (SALOME::SALOME_Exception)
325 {
326         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
327         
328         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
329         
330         try
331         {
332                 std::vector<std::string> listParts = mObj->getParts();
333                 mySeq->length(listParts.size());
334                 
335                 for (int i = 0 ; i < listParts.size() ; i++)
336         {
337                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
338         }
339         }
340         catch (multipr::RuntimeException& e)
341         {
342                 e.dump(cout);
343                 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
344         }
345         
346     return mySeq._retn();
347 }
348
349
350 char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
351         throw (SALOME::SALOME_Exception)
352 {
353         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
354         
355         return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str());
356 }
357
358
359 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
360         throw (SALOME::SALOME_Exception)
361 {
362         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
363         
364         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
365         
366         try
367         {
368                 std::vector<std::string> listParts = mObj->partitionneDomaine();
369                 mySeq->length(listParts.size());
370                 
371                 for (int i = 0 ; i < listParts.size() ; i++)
372         {
373                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
374         }
375         }
376         catch (multipr::RuntimeException& e)
377         {
378                 e.dump(cout);
379                 THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR);
380         }
381         
382     return mySeq._retn();
383 }
384
385
386 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGrain(
387                 const char* pPartName, 
388                 CORBA::Long pNbParts, 
389                 CORBA::Long pPartitionner)
390                 throw (SALOME::SALOME_Exception)
391 {
392         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
393         
394         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
395         
396         try
397         {
398                 std::vector<std::string> listParts = mObj->partitionneGrain(
399                         pPartName,
400                         pNbParts,
401                         pPartitionner);
402                         
403                 mySeq->length(listParts.size());
404                 
405                 for (int i = 0 ; i < listParts.size() ; i++)
406         {
407                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
408         }
409         }
410         catch (multipr::RuntimeException& e)
411         {
412                 e.dump(cout);
413                 THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR);
414         }
415         
416     return mySeq._retn();
417 }
418
419
420 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition(
421                 const char*   pPartName,
422                 const char*   pFieldName,
423                 CORBA::Long   pFieldIt,
424                 const char*   pFilterName,
425                 CORBA::Double pTmed,
426                 CORBA::Double pTlow,
427                 CORBA::Double pRadius)
428                 throw (SALOME::SALOME_Exception)
429 {
430         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
431         
432         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
433         
434         try
435         {
436                 std::vector<std::string> listParts = mObj->decimePartition(
437                         pPartName,
438                         pFieldName,
439                         pFieldIt,
440                         pFilterName,
441                         pTmed,
442                         pTlow,
443                         pRadius,
444                         mBoxing);
445                 
446                 mySeq->length(listParts.size());
447                 
448                 for (int i = 0 ; i < listParts.size() ; i++)
449         {
450                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
451         }
452         }
453         catch (multipr::RuntimeException& e)
454         {
455                 e.dump(cout);
456                 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
457         }
458         
459         return mySeq._retn();
460 }
461
462
463 char* MULTIPR_Obj_i::evalDecimationParams(
464         const char* pPartName, 
465         const char* pFieldName, 
466         CORBA::Long pFieldIt, 
467         const char* pFilterName,
468         const char* pFilterParams)
469         throw (SALOME::SALOME_Exception)
470 {
471         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
472         
473         try
474         {
475                 string res = mObj->evalDecimationParams(
476                         pPartName,
477                         pFieldName,
478                         pFieldIt,
479                         pFilterName,
480                         pFilterParams);
481                         
482                 return CORBA::string_dup(res.c_str());
483                         
484         }
485         catch (multipr::RuntimeException& e)
486         {
487                 e.dump(cout);
488                 THROW_SALOME_CORBA_EXCEPTION("Unable to evaluate decimation parameters", SALOME::INTERNAL_ERROR);
489         }
490 }
491
492
493 void MULTIPR_Obj_i::removeParts(const char* pPrefixPartName)
494         throw (SALOME::SALOME_Exception)
495 {
496         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
497         
498         mObj->removeParts(pPrefixPartName);
499 }
500
501
502 void MULTIPR_Obj_i::save(const char* pPath)
503         throw (SALOME::SALOME_Exception)
504 {
505         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
506         
507         try
508         {
509                 mObj->save(pPath);
510                 
511         }
512         catch (multipr::RuntimeException& e)
513         {
514                 e.dump(cout);
515                 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
516         }
517 }
518
519
520 extern "C"
521 {
522         PortableServer::ObjectId* MULTIPREngine_factory(
523                 CORBA::ORB_ptr orb,
524                 PortableServer::POA_ptr poa, 
525                 PortableServer::ObjectId * contId,
526                 const char* instanceName, 
527                 const char* interfaceName)
528         {
529                 MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()");
530                 SCRUTE(interfaceName);
531                 MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName);
532                 return myMULTIPR->getId();
533         }
534 }