Salome HOME
768cb438c2c5c6a751ce36f891507dccfa40dbf1
[modules/kernel.git] / src / DSC / DSC_Python / calcium.i
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 %define DOCSTRING
23 "CALCIUM python wrapping : Superv_Component class
24 "
25 %enddef
26
27 %module(docstring=DOCSTRING) calcium
28
29 %feature("autodoc", "1");
30
31 %{
32 //C++ Includes 
33 #include <SALOMEconfig.h>
34 #include <Calcium.hxx>
35 #include <calcium.h>
36 #include <Superv_Component_i.hxx>
37 #include <Salome_file_i.hxx>
38 #include <omniORB4/CORBA.h>
39
40 //--- from omniORBpy.h (not present on Debian Sarge packages)
41
42 struct omniORBpyAPI {
43
44   PyObject* (*cxxObjRefToPyObjRef)(const CORBA::Object_ptr cxx_obj,
45            CORBA::Boolean hold_lock);
46   // Convert a C++ object reference to a Python object reference.
47   // If <hold_lock> is true, caller holds the Python interpreter lock.
48
49   CORBA::Object_ptr (*pyObjRefToCxxObjRef)(PyObject* py_obj,
50              CORBA::Boolean hold_lock);
51   // Convert a Python object reference to a C++ object reference.
52   // Raises BAD_PARAM if the Python object is not an object reference.
53   // If <hold_lock> is true, caller holds the Python interpreter lock.
54
55   PyObject* (*handleCxxSystemException)(const CORBA::SystemException& ex);
56   // Sets the Python exception state to reflect the given C++ system
57   // exception. Always returns NULL. The caller must hold the Python
58   // interpreter lock.
59 };
60
61   omniORBpyAPI* api;
62   PyObject* dsc ;
63
64
65 %}
66
67 %init
68 %{
69   // init section
70
71 #ifdef WITH_NUMPY
72   import_array()
73 #endif
74
75   PyObject* omnipy = PyImport_ImportModule((char*)"_omnipy");
76   if (!omnipy)
77   {
78     PyErr_SetString(PyExc_ImportError,
79         (char*)"Cannot import _omnipy");
80     return;
81   }
82   PyObject* pyapi = PyObject_GetAttrString(omnipy, (char*)"API");
83   api = (omniORBpyAPI*)PyCObject_AsVoidPtr(pyapi);
84   Py_DECREF(pyapi);
85
86   PyObject* engines = PyImport_ImportModule("Engines");
87   dsc = PyObject_GetAttrString(engines, "DSC");
88 %}
89
90 %include <exception.i>
91
92
93
94 /*
95  * Most of this code is borrowed from numpy distribution
96  * The following code originally appeared in enthought/kiva/agg/src/numeric.i,
97  * author unknown.  It was translated from C++ to C by John Hunter.  Bill
98  * Spotz has modified it slightly to fix some minor bugs, add some comments
99  * and some functionality.
100  */
101
102 %{
103
104 #ifdef WITH_NUMPY
105 /* With Numpy */
106 #ifdef HAVE_ISINF
107 #undef HAVE_ISINF
108 #endif
109 #include <numpy/arrayobject.h>
110
111 typedef PyArrayObject ArrayObject;
112
113 /* Macros to extract array attributes.
114  */
115 #define is_array(a)            ((a) && PyArray_Check((PyArrayObject *)a))
116 #define array_type(a)          (int)(PyArray_TYPE(a))
117 #define array_dimensions(a)    (((PyArrayObject *)a)->nd)
118 #define array_size(a,i)        (((PyArrayObject *)a)->dimensions[i])
119 #define array_is_contiguous(a) (PyArray_ISCONTIGUOUS(a))
120
121 /* Given a PyObject, return a string describing its type.
122  */
123 const char* pytype_string(PyObject* py_obj) {
124   if (py_obj == NULL          ) return "C NULL value";
125   if (PyCallable_Check(py_obj)) return "callable"    ;
126   if (PyString_Check(  py_obj)) return "string"      ;
127   if (PyInt_Check(     py_obj)) return "int"         ;
128   if (PyFloat_Check(   py_obj)) return "float"       ;
129   if (PyDict_Check(    py_obj)) return "dict"        ;
130   if (PyList_Check(    py_obj)) return "list"        ;
131   if (PyTuple_Check(   py_obj)) return "tuple"       ;
132   if (PyFile_Check(    py_obj)) return "file"        ;
133   if (PyModule_Check(  py_obj)) return "module"      ;
134   if (PyInstance_Check(py_obj)) return "instance"    ;
135
136   return "unkown type";
137 }
138
139 /*
140 For documentation only : numpy typecodes
141
142 enum NPY_TYPECHAR { NPY_BOOLLTR = '?',
143                         NPY_BYTELTR = 'b',
144                         NPY_UBYTELTR = 'B',
145                         NPY_SHORTLTR = 'h',
146                         NPY_USHORTLTR = 'H',
147                         NPY_INTLTR = 'i',
148                         NPY_UINTLTR = 'I',
149                         NPY_LONGLTR = 'l',
150                         NPY_ULONGLTR = 'L',
151                         NPY_LONGLONGLTR = 'q',
152                         NPY_ULONGLONGLTR = 'Q',
153                         NPY_FLOATLTR = 'f',
154                         NPY_DOUBLELTR = 'd',
155                         NPY_LONGDOUBLELTR = 'g',
156                         NPY_CFLOATLTR = 'F',
157                         NPY_CDOUBLELTR = 'D',
158                         NPY_CLONGDOUBLELTR = 'G',
159                         NPY_OBJECTLTR = 'O',
160                         NPY_STRINGLTR = 'S',
161                         NPY_STRINGLTR2 = 'a',
162                         NPY_UNICODELTR = 'U',
163                         NPY_VOIDLTR = 'V',
164                         NPY_CHARLTR = 'c',
165
166                         NPY_INTPLTR = 'p',
167                         NPY_UINTPLTR = 'P',
168
169                         NPY_GENBOOLLTR ='b',
170                         NPY_SIGNEDLTR = 'i',
171                         NPY_UNSIGNEDLTR = 'u',
172                         NPY_FLOATINGLTR = 'f',
173                         NPY_COMPLEXLTR = 'c'
174 };
175 */
176
177 /* Given a Numeric typecode, return a string describing the type.
178  */
179 const char* typecode_string(int typecode) {
180   const char* type_names[] = {"bool","byte","unsigned byte","short",
181         "unsigned short","int","unsigned int","long","unsigned long",
182         "longlong","unsigned longlong",
183         "float","double","long double","complex float","complex double","complex long double",
184         "object","string","unicode","void","ntypes","notype","char","unkown"};
185   return type_names[typecode];
186 }
187
188 /* Make sure input has correct numeric type.  Allow character and byte
189  * to match.  Also allow int and long to match.
190  */
191 int type_match(int actual_type, int desired_type) {
192   return PyArray_EquivTypenums(actual_type, desired_type);
193 }
194
195 /* Given a PyObject pointer, cast it to a PyArrayObject pointer if
196  * legal.  If not, set the python error string appropriately and
197  * return NULL./
198  */
199 PyArrayObject* obj_to_array_no_conversion(PyObject* input, int typecode) {
200   PyArrayObject* ary = NULL;
201   if (is_array(input) && (typecode == PyArray_NOTYPE ||
202         PyArray_EquivTypenums(array_type(input),
203             typecode))) {
204         ary = (PyArrayObject*) input;
205     }
206     else if is_array(input) {
207       const char* desired_type = typecode_string(typecode);
208       const char* actual_type = typecode_string(array_type(input));
209       PyErr_Format(PyExc_TypeError,
210        "Array of type '%s' required.  Array of type '%s' given",
211        desired_type, actual_type);
212       ary = NULL;
213     }
214     else {
215       const char * desired_type = typecode_string(typecode);
216       const char * actual_type = pytype_string(input);
217       PyErr_Format(PyExc_TypeError,
218        "Array of type '%s' required.  A %s was given",
219        desired_type, actual_type);
220       ary = NULL;
221     }
222   return ary;
223 }
224
225 /* Convert the given PyObject to a Numeric array with the given
226  * typecode.  On Success, return a valid PyArrayObject* with the
227  * correct type.  On failure, the python error string will be set and
228  * the routine returns NULL.
229  */
230 PyArrayObject* obj_to_array_allow_conversion(PyObject* input, int typecode,
231                                              int* is_new_object)
232 {
233   PyArrayObject* ary = NULL;
234   PyObject* py_obj;
235   if (is_array(input) && (typecode == PyArray_NOTYPE || type_match(array_type(input),typecode))) {
236     ary = (PyArrayObject*) input;
237     *is_new_object = 0;
238   }
239   else {
240     py_obj = PyArray_FromObject(input, typecode, 0, 0);
241     /* If NULL, PyArray_FromObject will have set python error value.*/
242     ary = (PyArrayObject*) py_obj;
243     *is_new_object = 1;
244   }
245   return ary;
246 }
247
248 /* Given a PyArrayObject, check to see if it is contiguous.  If so,
249  * return the input pointer and flag it as not a new object.  If it is
250  * not contiguous, create a new PyArrayObject using the original data,
251  * flag it as a new object and return the pointer.
252  */
253 PyArrayObject* make_contiguous(PyArrayObject* ary, int* is_new_object,
254                                int min_dims, int max_dims)
255 {
256   PyArrayObject* result;
257   if (array_is_contiguous(ary)) {
258     result = ary;
259     *is_new_object = 0;
260   }
261   else {
262     result = (PyArrayObject*) PyArray_ContiguousFromObject((PyObject*)ary,
263                  array_type(ary),
264                  min_dims,
265                  max_dims);
266     *is_new_object = 1;
267   }
268   return result;
269 }
270
271 /* Convert a given PyObject to a contiguous PyArrayObject of the
272  * specified type.  If the input object is not a contiguous
273  * PyArrayObject, a new one will be created and the new object flag
274  * will be set.
275  */
276 PyArrayObject* obj_to_array_contiguous_allow_conversion(PyObject* input,
277                                                         int typecode,
278                                                         int* is_new_object) {
279   int is_new1 = 0;
280   int is_new2 = 0;
281   PyArrayObject* ary2;
282   PyArrayObject* ary1 = obj_to_array_allow_conversion(input, typecode,
283                   &is_new1);
284   if (ary1) {
285     ary2 = make_contiguous(ary1, &is_new2, 0, 0);
286     if ( is_new1 && is_new2) {
287       Py_DECREF(ary1);
288     }
289     ary1 = ary2;
290   }
291   *is_new_object = is_new1 || is_new2;
292   return ary1;
293 }
294
295 /* Test whether a python object is contiguous.  If array is
296  * contiguous, return 1.  Otherwise, set the python error string and
297  * return 0.
298  */
299 int require_contiguous(PyArrayObject* ary) {
300   int contiguous = 1;
301   if (!array_is_contiguous(ary)) {
302     PyErr_SetString(PyExc_TypeError, "Array must be contiguous.  A discontiguous array was given");
303     contiguous = 0;
304   }
305   return contiguous;
306 }
307
308 /* Require the given PyArrayObject to have a specified number of
309  * dimensions.  If the array has the specified number of dimensions,
310  * return 1.  Otherwise, set the python error string and return 0.
311  */
312 int require_dimensions(PyArrayObject* ary, int exact_dimensions) {
313   int success = 1;
314   if (array_dimensions(ary) != exact_dimensions) {
315     PyErr_Format(PyExc_TypeError,
316      "Array must have %d dimensions.  Given array has %d dimensions",
317      exact_dimensions, array_dimensions(ary));
318     success = 0;
319   }
320   return success;
321 }
322
323 /* Require the given PyArrayObject to have one of a list of specified
324  * number of dimensions.  If the array has one of the specified number
325  * of dimensions, return 1.  Otherwise, set the python error string
326  * and return 0.
327  */
328 int require_dimensions_n(PyArrayObject* ary, int* exact_dimensions, int n) {
329   int success = 0;
330   int i;
331   char dims_str[255] = "";
332   char s[255];
333   for (i = 0; i < n && !success; i++) {
334     if (array_dimensions(ary) == exact_dimensions[i]) {
335       success = 1;
336     }
337   }
338   if (!success) {
339     for (i = 0; i < n-1; i++) {
340       sprintf(s, "%d, ", exact_dimensions[i]);
341       strcat(dims_str,s);
342     }
343     sprintf(s, " or %d", exact_dimensions[n-1]);
344     strcat(dims_str,s);
345     PyErr_Format(PyExc_TypeError,
346      "Array must have %s dimensions.  Given array has %d dimensions",
347      dims_str, array_dimensions(ary));
348   }
349   return success;
350 }
351
352 /* Require the given PyArrayObject to have a specified shape.  If the
353  * array has the specified shape, return 1.  Otherwise, set the python
354  * error string and return 0.
355  */
356 int require_size(PyArrayObject* ary, int* size, int n) {
357   int i;
358   int success = 1;
359   int len;
360   char desired_dims[255] = "[";
361   char s[255];
362   char actual_dims[255] = "[";
363   for(i=0; i < n;i++) {
364     if (size[i] != -1 &&  size[i] != array_size(ary,i)) {
365       success = 0;
366     }
367   }
368   if (!success) {
369     for (i = 0; i < n; i++) {
370       if (size[i] == -1) {
371         sprintf(s, "*,");
372       }
373       else
374       {
375         sprintf(s, "%d,", size[i]);
376       }
377       strcat(desired_dims,s);
378     }
379     len = strlen(desired_dims);
380     desired_dims[len-1] = ']';
381     for (i = 0; i < n; i++) {
382       sprintf(s, "%d,", array_size(ary,i));
383       strcat(actual_dims,s);
384     }
385     len = strlen(actual_dims);
386     actual_dims[len-1] = ']';
387     PyErr_Format(PyExc_TypeError,
388      "Array must have shape of %s.  Given array has shape of %s",
389      desired_dims, actual_dims);
390   }
391   return success;
392 }
393
394 #else
395 /* Without Numpy */
396 typedef PyObject ArrayObject;
397
398 #endif
399 %}
400
401 %include "carrays.i" 
402
403 %array_class(int, intArray);
404 %array_class(float, floatArray);
405 %array_class(double, doubleArray);
406
407 /* special struct to handle string arrays */
408 %inline %{
409 struct stringArray
410 {
411   stringArray(int nelements,int size=0) {
412     nelem=nelements;
413     data= new char*[nelements];
414     for(int i=0;i<nelements;i++)
415     {
416       data[i]=(char *)malloc((size+1)*sizeof(char));
417       data[i][size+1]='\0';
418     }
419   }
420   ~stringArray() 
421   {
422     std::cerr << "~stringArray() " << nelem << std::endl;
423     for(int i=0;i<nelem;i++)
424       free(data[i]);
425     delete [] data;
426   }
427   char* __getitem__(int index) {
428     return data[index];
429   }
430   void __setitem__(int index, char* value) {
431     free(data[index]);
432     data[index] = strdup(value);
433   }
434   char** data;
435   int nelem;
436 };
437 %}
438 /* End of special struct to handle string arrays */
439
440 /* input typemap 
441    This typemap can be used for input array objects only.
442    It accepts swig carray objects or numpy contiguous or non contiguous objects.
443    In case of non-contiguous numpy object, it is converted (new object) into a contiguous numpy object
444    This new object is deleted after the call.
445 */
446 %define TYPEMAP_IN3(type,typecode)
447 %typemap(in) type* IN_ARRAY3
448              (ArrayObject* array=NULL, int is_new_object) {
449   if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0)) == -1)
450   {
451 %#ifdef WITH_NUMPY
452     int size[1] = {-1};
453     array = obj_to_array_contiguous_allow_conversion($input, typecode, &is_new_object);
454     if (!array || !require_dimensions(array,1) || !require_size(array,size,1)) SWIG_fail;
455     $1 = (type*) array->data;
456 %#else
457     SWIG_exception(SWIG_TypeError, "type* expected");
458 %#endif
459   }
460 }
461 %typemap(freearg) type* IN_ARRAY3 {
462   if (is_new_object$argnum && array$argnum) Py_DECREF(array$argnum);
463 }
464 %enddef
465
466 TYPEMAP_IN3(int,     PyArray_INT)
467 TYPEMAP_IN3(float,   PyArray_FLOAT )
468 TYPEMAP_IN3(double,  PyArray_DOUBLE)
469
470 #undef TYPEMAP_IN3
471
472 %apply int*    IN_ARRAY3 {int    *eval};
473 %apply float*  IN_ARRAY3 {float  *eval};
474 %apply double* IN_ARRAY3 {double *eval};
475
476 /*  Specific typemap for complex */
477 %typemap(in) float*  ecpval
478              (ArrayObject* array=NULL, int is_new_object) {
479   if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0)) == -1)
480   {
481 %#ifdef WITH_NUMPY
482     int size[1] = {-1};
483     array = obj_to_array_contiguous_allow_conversion($input, PyArray_CFLOAT, &is_new_object);
484     if (!array || !require_dimensions(array,1) || !require_size(array,size,1)) SWIG_fail;
485     $1 = (float*) array->data;
486 %#else
487     SWIG_exception(SWIG_TypeError, "complex array expected");
488 %#endif
489   }
490 }
491 %typemap(freearg) float* ecpval {
492   if (is_new_object$argnum && array$argnum) Py_DECREF(array$argnum);
493 }
494 /* End of  Specific typemap for complex */
495
496 /* array of strings on input */
497 %typemap(in) char** eval
498          (ArrayObject* array=NULL, int is_new_object) {
499   stringArray* sarray;
500   if ((SWIG_ConvertPtr($input, (void **) &sarray, $descriptor(stringArray *),0)) == -1)
501   {
502 %#ifdef WITH_NUMPY
503     int size[1] = {-1};
504     array = obj_to_array_contiguous_allow_conversion($input, PyArray_STRING, &is_new_object);
505     if (!array || !require_dimensions(array,1) || !require_size(array,size,1)) SWIG_fail;
506     $1 = (char**) malloc(array_size(array,0)*sizeof(char*));
507     for(int i=0;i<array_size(array,0);i++)
508       $1[i]=(char*) array->data + i* array->strides[0];
509 %#else
510     SWIG_exception(SWIG_TypeError, "string array expected");
511 %#endif
512   }
513   else
514   {
515     $1=sarray->data;
516   }
517 }
518
519 %typemap(freearg) char** eval {
520   if (array$argnum) free($1);
521   if (is_new_object$argnum && array$argnum) Py_DECREF(array$argnum);
522 }
523 /* End of array of strings on input */
524
525 /* inplace typemaps 
526    This typemap can be used for input/output array objects.
527    It accepts swig carray objects or numpy contiguous objects.
528 */
529
530 %define TYPEMAP_INPLACE3(type,typecode)
531 %typemap(in) type* INPLACE_ARRAY3 (ArrayObject* temp=NULL) {
532   if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0)) == -1)
533   {
534 %#ifdef WITH_NUMPY
535     temp = obj_to_array_no_conversion($input,typecode);
536     if (!temp  || !require_contiguous(temp)) SWIG_fail;
537     $1 = (type*) temp->data;
538 %#else
539     temp = NULL;
540     SWIG_exception(SWIG_TypeError, "type* expected");
541 %#endif
542   }
543 }
544 %enddef
545
546 TYPEMAP_INPLACE3(int,     PyArray_INT)
547 TYPEMAP_INPLACE3(float,   PyArray_FLOAT )
548 TYPEMAP_INPLACE3(double,  PyArray_DOUBLE)
549
550 #undef TYPEMAP_INPLACE3
551
552 %apply int*    INPLACE_ARRAY3 {int    *lval};
553 %apply float*  INPLACE_ARRAY3 {float  *lval};
554 %apply double* INPLACE_ARRAY3 {double *lval};
555
556 /*  typemap for complex inout */
557 %typemap(in) float* lcpval
558              (ArrayObject* temp=NULL) {
559   if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0)) == -1)
560   {
561 %#ifdef WITH_NUMPY
562     temp = obj_to_array_no_conversion($input,PyArray_CFLOAT);
563     if (!temp  || !require_contiguous(temp)) SWIG_fail;
564     $1 = (float*) temp->data;
565 %#else
566     temp = NULL;
567     SWIG_exception(SWIG_TypeError, "complex array expected");
568 %#endif
569   }
570 }
571 /*  End of typemap for complex inout */
572
573 /* typemap for array of strings on input/output */
574 %typemap(in) char** lval
575             (ArrayObject* temp=NULL) {
576   stringArray* sarray;
577   if ((SWIG_ConvertPtr($input, (void **) &sarray, $descriptor(stringArray *) ,0)) == -1)
578   {
579 %#ifdef WITH_NUMPY
580     temp = obj_to_array_no_conversion($input,PyArray_STRING);
581     if (!temp  || !require_contiguous(temp)) SWIG_fail;
582     $1 = (char**) malloc(array_size(temp,0)*sizeof(char*));
583     for(int i=0;i<array_size(temp,0);i++)
584       $1[i]=(char*) temp->data+i*temp->strides[0];
585 %#else
586     temp = NULL;
587     SWIG_exception(SWIG_TypeError, "string array expected");
588 %#endif
589   }
590   else
591   {
592     $1=sarray->data;
593   }
594 }
595 %typemap(freearg) char** lval {
596   if (temp$argnum) free($1);
597 }
598 /* End of typemap for array of strings on input/output */
599
600 %typemap(in) CORBA::Boolean
601 {
602   $1=(CORBA::Boolean)PyInt_AsLong($input);
603 }
604 %typemap(out) CORBA::Boolean
605 {
606   $result=PyInt_FromLong($1 ? 1 : 0);
607 }
608
609 %define CORBAPTR(type)
610 %typemap(in) type##_ptr
611 {
612   Py_BEGIN_ALLOW_THREADS
613   try
614   {
615      CORBA::Object_var obj = api->pyObjRefToCxxObjRef($input,0);
616      $1 = type##::_narrow(obj);
617   }
618   catch(...)
619   {
620      Py_BLOCK_THREADS
621      PyErr_SetString(PyExc_RuntimeError, "not a valid CORBA object ptr");
622   }
623   Py_END_ALLOW_THREADS
624 }
625 %typemap(freearg) type##_ptr {
626   CORBA::release($1);
627 }
628 %enddef
629
630 CORBAPTR(CORBA::ORB)
631 CORBAPTR(Ports::PortProperties)
632 CORBAPTR(Ports::Port)
633 CORBAPTR(Engines::Container)
634 CORBAPTR(PortableServer::POA)
635
636 %typemap(out) Ports::Port_ptr 
637 {
638   $result = api->cxxObjRefToPyObjRef($1, 1);
639   //All output Ports::Port_ptr variables are duplicated by security. Need to release them for python . Explanation ??
640   CORBA::release($1);
641 }
642
643 %typemap(out) Ports::PortProperties_ptr, Engines::Salome_file_ptr
644 {
645   $result = api->cxxObjRefToPyObjRef($1, 1);
646 }
647
648 %typemap(out) Engines::DSC::uses_port *
649 {
650    $result = PyList_New($1->length());
651    for (CORBA::ULong i=0; i < $1->length() ; i++)
652      PyList_SetItem($result,i,api->cxxObjRefToPyObjRef((*$1)[i], 1));
653    //delete the copy (created by new) of uses port sequence
654    delete $1;
655 }
656
657 /*
658  * Exception section
659  */
660 // a general exception handler
661 %exception {
662    Py_BEGIN_ALLOW_THREADS
663    try {
664       $action
665    }
666    catch(Engines::DSC::PortNotDefined& _e) {
667       Py_BLOCK_THREADS
668       PyObject* excc = PyObject_GetAttrString(dsc, "PortNotDefined");
669       PyObject* exci = PyEval_CallObject(excc, (PyObject *)NULL);
670       PyErr_SetObject(excc, exci);
671       Py_XDECREF(excc);
672       Py_XDECREF(exci);
673       return NULL;
674    }
675    catch(Engines::DSC::PortNotConnected& _e) {
676       Py_BLOCK_THREADS
677       PyObject* excc = PyObject_GetAttrString(dsc, "PortNotConnected");
678       PyObject* exci = PyEval_CallObject(excc, (PyObject *)NULL);
679       PyErr_SetObject(excc, exci);
680       Py_XDECREF(excc);
681       Py_XDECREF(exci);
682       return NULL;
683    }
684    catch(Engines::DSC::BadPortType& _e) {
685       Py_BLOCK_THREADS
686       PyObject* excc = PyObject_GetAttrString(dsc, "BadPortType");
687       PyObject* exci = PyEval_CallObject(excc, (PyObject *)NULL);
688       PyErr_SetObject(excc, exci);
689       Py_XDECREF(excc);
690       Py_XDECREF(exci);
691       return NULL;
692    }
693    catch (SALOME_Exception &e) {
694       Py_BLOCK_THREADS
695       PyErr_SetString(PyExc_RuntimeError,e.what());
696       return NULL;
697    }
698    catch (SALOME::SALOME_Exception &e) {
699       Py_BLOCK_THREADS
700       //This one should be converted into a python corba exception
701       PyErr_SetString(PyExc_RuntimeError,e.details.text);
702       return NULL;
703    }
704    catch (const CORBA::SystemException& e) {
705       Py_BLOCK_THREADS 
706       return api->handleCxxSystemException(e);
707    }
708    catch(...) {
709       Py_BLOCK_THREADS
710       PyErr_SetString(PyExc_ValueError,"Unknown exception");
711       return NULL;
712    }
713    Py_END_ALLOW_THREADS
714 }
715
716 /*
717  * End of Exception section
718  */
719 namespace Engines
720 {
721 class DSC
722 {
723   public:
724     enum Message { AddingConnection, RemovingConnection, ApplicationError };
725 };
726 }
727
728 class PySupervCompo:public Superv_Component_i
729 {
730   public:
731
732     PySupervCompo(CORBA::ORB_ptr orb,
733          PortableServer::POA_ptr poa,
734          Engines::Container_ptr contai,
735          const char *instanceName,
736          const char *interfaceName);
737
738     virtual ~PySupervCompo();
739     CORBA::Boolean init_service(const char * service_name){return true;};
740     virtual provides_port * create_provides_data_port(const char* port_fab_type)
741         throw (BadFabType);
742     virtual uses_port * create_uses_data_port(const char* port_fab_type)
743         throw (BadFabType);
744     virtual void add_port(const char * port_fab_type,
745         const char * port_type,
746         const char * port_name)
747         throw (PortAlreadyDefined, BadFabType, BadType, BadProperty);
748     template < typename SpecificPortType >
749     SpecificPortType * add_port(const char * port_fab_type,
750             const char * port_type,
751             const char * port_name)
752           throw (PortAlreadyDefined, BadFabType, BadType, BadCast, BadProperty);
753     virtual void add_port(provides_port * port,
754           const char* provides_port_name)
755           throw (PortAlreadyDefined, NilPort, BadProperty);
756     virtual void add_port(uses_port * port,
757           const char* uses_port_name)
758           throw (PortAlreadyDefined, NilPort, BadProperty);
759     template <typename SpecificPortType >
760     SpecificPortType * get_port( const char * port_name)
761           throw (PortNotDefined, PortNotConnected, BadCast, UnexpectedState);
762     virtual Ports::Port_ptr get_provides_port(const char* provides_port_name,
763               const CORBA::Boolean connection_error)
764               throw (Engines::DSC::PortNotDefined,
765                      Engines::DSC::PortNotConnected,
766                      Engines::DSC::BadPortType);
767     virtual void connect_uses_port(const char* uses_port_name,
768                          Ports::Port_ptr provides_port_ref)
769               throw (Engines::DSC::PortNotDefined,
770                      Engines::DSC::BadPortType,
771                      Engines::DSC::NilPort);
772     virtual void connect_provides_port(const char* provides_port_name)
773               throw (Engines::DSC::PortNotDefined);
774     virtual void disconnect_provides_port(const char* provides_port_name,
775               const Engines::DSC::Message message)
776               throw (Engines::DSC::PortNotDefined,
777                      Engines::DSC::PortNotConnected);
778
779     virtual void disconnect_uses_port(const char* uses_port_name,
780                   Ports::Port_ptr provides_port_ref,
781                   const Engines::DSC::Message message)
782               throw (Engines::DSC::PortNotDefined,
783                      Engines::DSC::PortNotConnected,
784                      Engines::DSC::BadPortReference);
785
786     virtual Ports::PortProperties_ptr get_port_properties(const char* port_name);
787
788 // Interface for Salome_file
789     Engines::Salome_file_ptr getInputFileToService(const char* service_name, const char* Salome_file_name);
790     void checkInputFilesToService(const char* service_name);
791     Engines::Salome_file_ptr setInputFileToService(const char* service_name, const char* Salome_file_name);
792     Engines::Salome_file_ptr getOutputFileToService(const char* service_name, const char* Salome_file_name);
793     void checkOutputFilesToService(const char* service_name);
794     Engines::Salome_file_ptr setOutputFileToService(const char* service_name, const char* Salome_file_name);
795 // End of Interface for Salome_file
796
797 // DSC interface for python components
798   virtual void add_provides_port(Ports::Port_ptr ref, const char* provides_port_name, Ports::PortProperties_ptr port_prop);
799   virtual void add_uses_port(const char* repository_id, const char* uses_port_name, Ports::PortProperties_ptr port_prop);
800   virtual Engines::DSC::uses_port * get_uses_port(const char* uses_port_name);
801   CORBA::Boolean is_connected(const char* port_name) throw (Engines::DSC::PortNotDefined);
802 // End of DSC interface for python components
803
804
805
806     %extend
807       {
808        //To get the address of the component
809         long ptr()
810         {
811           return (long)self;
812         }
813       }
814 };
815
816 %apply int *OUTPUT { int *nval };
817 %apply float *INOUT { float  *ti };
818 %apply float *INPUT { float  *tf };
819 %apply int *INOUT { int  *niter };
820 %apply double *INOUT { double  *ti };
821 %apply double *INPUT { double  *tf };
822
823 extern "C" void create_calcium_port(Superv_Component_i* compo,char* name,char* type,char *mode,char* depend);
824
825 %ignore CPMESSAGE;
826 %include "calciumP.h"
827
828 int  cp_cd(Superv_Component_i *component,char *name);
829
830 int cp_een(Superv_Component_i *component,int dep,float  t,int n,char *nom,int nval,int    *eval);
831 int cp_edb(Superv_Component_i *component,int dep,double t,int n,char *nom,int nval,double *eval);
832 int cp_ere(Superv_Component_i *component,int dep,float  t,int n,char *nom,int nval,float  *eval);
833 int cp_ecp(Superv_Component_i *component,int dep,float  t,int n,char *nom,int nval,float  *ecpval);
834 int cp_elo(Superv_Component_i *component,int dep,float  t,int n,char *nom,int nval,int    *eval);
835 int cp_ech(Superv_Component_i *component,int dep,float  t,int n,char *nom,int nval,char** eval,int strSize);
836
837
838 int cp_len(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,int    *lval);
839 int cp_ldb(Superv_Component_i *component,int dep,double *ti,double *tf,int *niter,char *nom,int nmax,int *nval,double *lval);
840 int cp_lre(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,float  *lval);
841 int cp_lcp(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,float  *lcpval);
842 int cp_llo(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,int    *lval);
843 int cp_lch(Superv_Component_i *component,int dep,float  *ti,float  *tf,int *niter,char *nom,int nmax,int *nval,char** lval,int strSize);
844
845 int cp_fin(Superv_Component_i *component,int cp_end);
846