]> SALOME platform Git repositories - modules/multipr.git/blob - src/MULTIPR/MULTIPR_i.cxx
Salome HOME
*** empty log message ***
[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                 delete mObj;
190                 mObj = NULL;
191         }
192 }
193
194
195 CORBA::Boolean MULTIPR_Obj_i::isValidSequentialMEDFile()
196                 throw (SALOME::SALOME_Exception)
197 {
198         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
199         
200         return mObj->isValidSequentialMEDFile();
201 }
202
203
204 CORBA::Boolean MULTIPR_Obj_i::isValidDistributedMEDFile()
205         throw (SALOME::SALOME_Exception)
206 {
207         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
208         
209         return mObj->isValidDistributedMEDFile();
210 }
211
212
213 void MULTIPR_Obj_i::setMesh(const char* meshName)
214                 throw (SALOME::SALOME_Exception)
215 {
216         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
217         
218         try
219         {
220                 mObj->setMesh(meshName);
221                 
222                 cout << "Set mesh OK" << endl << endl;
223         }
224         catch (multipr::RuntimeException& e)
225         {
226                 e.dump(cout);
227                 THROW_SALOME_CORBA_EXCEPTION("Unable to set mesh", SALOME::INTERNAL_ERROR);
228         }
229 }
230
231
232 void MULTIPR_Obj_i::setBoxing(CORBA::Long pBoxing)
233         throw (SALOME::SALOME_Exception)
234 {
235         if (mBoxing < 0) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be >= 1", SALOME::INTERNAL_ERROR);
236         if (mBoxing > 200) THROW_SALOME_CORBA_EXCEPTION("Invalid boxing parameter; should be <= 200", SALOME::INTERNAL_ERROR);
237         
238         mBoxing = pBoxing;
239 }
240
241
242 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getMeshes() 
243         throw (SALOME::SALOME_Exception)
244 {
245         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
246         
247         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
248         
249         try
250         {
251                 std::vector<std::string> listMeshes = mObj->getMeshes();
252                 mySeq->length(listMeshes.size());
253                 
254                 for (int i = 0 ; i < listMeshes.size() ; i++)
255         {
256                 mySeq[i] = CORBA::string_dup(listMeshes[i].c_str());
257         }
258         }
259         catch (multipr::RuntimeException& e)
260         {
261                 e.dump(cout);
262                 THROW_SALOME_CORBA_EXCEPTION("Unable to get meshes", SALOME::INTERNAL_ERROR);
263         }
264         
265     return mySeq._retn();
266 }
267
268
269 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getFields() 
270         throw (SALOME::SALOME_Exception)
271 {
272         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
273         
274         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
275         
276         try
277         {
278                 std::vector<std::string> listFields = mObj->getFields();
279                 mySeq->length(listFields.size());
280                 
281                 for (int i = 0 ; i < listFields.size() ; i++)
282         {
283                 mySeq[i] = CORBA::string_dup(listFields[i].c_str());
284         }
285         }
286         catch (multipr::RuntimeException& e)
287         {
288                 e.dump(cout);
289                 THROW_SALOME_CORBA_EXCEPTION("Unable to get fields", SALOME::INTERNAL_ERROR);
290         }
291         
292     return mySeq._retn();
293 }
294
295
296 CORBA::Long MULTIPR_Obj_i::getTimeStamps(const char* fieldName)
297         throw (SALOME::SALOME_Exception)
298 {
299         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
300         
301         try
302         {
303                 return mObj->getTimeStamps(fieldName);
304         }
305         catch (multipr::RuntimeException& e)
306         {
307                 e.dump(cout);
308                 THROW_SALOME_CORBA_EXCEPTION("Unable to get time stamps", SALOME::INTERNAL_ERROR);
309         }
310 }
311
312
313 MULTIPR_ORB::string_array* MULTIPR_Obj_i::getParts()
314         throw (SALOME::SALOME_Exception)
315 {
316         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
317         
318         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
319         
320         try
321         {
322                 std::vector<std::string> listParts = mObj->getParts();
323                 mySeq->length(listParts.size());
324                 
325                 for (int i = 0 ; i < listParts.size() ; i++)
326         {
327                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
328         }
329         }
330         catch (multipr::RuntimeException& e)
331         {
332                 e.dump(cout);
333                 THROW_SALOME_CORBA_EXCEPTION("Unable to get parts", SALOME::INTERNAL_ERROR);
334         }
335         
336     return mySeq._retn();
337 }
338
339
340 char* MULTIPR_Obj_i::getPartInfo(const char* pPartName)
341         throw (SALOME::SALOME_Exception)
342 {
343         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
344         
345         return CORBA::string_dup(mObj->getPartInfo(pPartName).c_str());
346 }
347
348
349 void MULTIPR_Obj_i::removePart(const char* pPartName)
350         throw (SALOME::SALOME_Exception)
351 {
352         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
353         
354         mObj->removeParts(pPartName);
355 }
356
357
358 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneDomaine()
359         throw (SALOME::SALOME_Exception)
360 {
361         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
362         
363         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
364         
365         try
366         {
367                 std::vector<std::string> listParts = mObj->partitionneDomaine();
368                 mySeq->length(listParts.size());
369                 
370                 for (int i = 0 ; i < listParts.size() ; i++)
371         {
372                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
373         }
374         }
375         catch (multipr::RuntimeException& e)
376         {
377                 e.dump(cout);
378                 THROW_SALOME_CORBA_EXCEPTION("Unable to partition mesh", SALOME::INTERNAL_ERROR);
379         }
380         
381     return mySeq._retn();
382 }
383
384
385 MULTIPR_ORB::string_array* MULTIPR_Obj_i::partitionneGrain(
386                 const char* pPartName, 
387                 CORBA::Long pNbParts, 
388                 CORBA::Long pPartitionner)
389                 throw (SALOME::SALOME_Exception)
390 {
391         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
392         
393         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
394         
395         try
396         {
397                 std::vector<std::string> listParts = mObj->partitionneGrain(
398                         pPartName,
399                         pNbParts,
400                         pPartitionner);
401                         
402                 mySeq->length(listParts.size());
403                 
404                 for (int i = 0 ; i < listParts.size() ; i++)
405         {
406                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
407         }
408         }
409         catch (multipr::RuntimeException& e)
410         {
411                 e.dump(cout);
412                 THROW_SALOME_CORBA_EXCEPTION("Unable to partition group", SALOME::INTERNAL_ERROR);
413         }
414         
415     return mySeq._retn();
416 }
417
418
419 MULTIPR_ORB::string_array* MULTIPR_Obj_i::decimePartition(
420                 const char*   pPartName,
421                 const char*   pFieldName,
422                 CORBA::Long   pFieldIt,
423                 const char*   pFilterName,
424                 CORBA::Double pTmed,
425                 CORBA::Double pTlow,
426                 CORBA::Double pRadius)
427                 throw (SALOME::SALOME_Exception)
428 {
429         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
430         
431         MULTIPR_ORB::string_array_var mySeq = new MULTIPR_ORB::string_array();
432         
433         try
434         {
435                 std::vector<std::string> listParts = mObj->decimePartition(
436                         pPartName,
437                         pFieldName,
438                         pFieldIt,
439                         pFilterName,
440                         pTmed,
441                         pTlow,
442                         pRadius,
443                         mBoxing);
444                 
445                 mySeq->length(listParts.size());
446                 
447                 for (int i = 0 ; i < listParts.size() ; i++)
448         {
449                 mySeq[i] = CORBA::string_dup(listParts[i].c_str());
450         }
451         }
452         catch (multipr::RuntimeException& e)
453         {
454                 e.dump(cout);
455                 THROW_SALOME_CORBA_EXCEPTION("Unable to decimate", SALOME::INTERNAL_ERROR);
456         }
457         
458         return mySeq._retn();
459 }
460
461
462 void MULTIPR_Obj_i::save()
463         throw (SALOME::SALOME_Exception)
464 {
465         if (mObj == NULL) THROW_SALOME_CORBA_EXCEPTION("No associated MED file", SALOME::INTERNAL_ERROR);
466         
467         try
468         {
469                 mObj->save();
470                 
471         }
472         catch (multipr::RuntimeException& e)
473         {
474                 e.dump(cout);
475                 THROW_SALOME_CORBA_EXCEPTION("Unable to save MED file", SALOME::INTERNAL_ERROR);
476         }
477 }
478
479
480 extern "C"
481 {
482         PortableServer::ObjectId* MULTIPREngine_factory(
483                 CORBA::ORB_ptr orb,
484                 PortableServer::POA_ptr poa, 
485                 PortableServer::ObjectId * contId,
486                 const char* instanceName, 
487                 const char* interfaceName)
488         {
489                 MESSAGE("PortableServer::ObjectId* MULTIPREngine_factory()");
490                 SCRUTE(interfaceName);
491                 MULTIPR_Gen_i* myMULTIPR = new MULTIPR_Gen_i(orb, poa, contId, instanceName, interfaceName);
492                 return myMULTIPR->getId();
493         }
494 }