Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / runtime / CORBAPorts.cxx
index fa478721f60b836bb109b41ccc1579fad21950ad..1f11b22728ac7f38774c2a6161477466d30ca624 100644 (file)
@@ -1,5 +1,23 @@
-
+//  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 //#define REFCNT
+//
 #ifdef REFCNT
 #define private public
 #define protected public
@@ -11,6 +29,7 @@
 #include "TypeConversions.hxx"
 #include "TypeCode.hxx"
 #include "CORBAPorts.hxx"
+#include "PythonPorts.hxx"
 #include "ServiceNode.hxx"
 #include "ComponentInstance.hxx"
 #include "SALOME_GenericObj.hh"
@@ -137,6 +156,7 @@ void InputCorbaPort::put(CORBA::Any *data) throw (ConversionException)
 
   // make a copy of the any (protect against deletion of any source)
   _data=*data;
+  _stringRef="";
 
   registerObj(_data);
 
@@ -167,6 +187,28 @@ CORBA::Any * InputCorbaPort::getAny()
   return &_data;
 }
 
+PyObject * InputCorbaPort::getPyObj()
+{
+  CORBA::TypeCode_var tc=getAny()->type();
+  if (!tc->equivalent(CORBA::_tc_null))
+    return convertCorbaPyObject(edGetType(),getAny());
+  else
+    {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
+}
+
+std::string InputCorbaPort::getAsString()
+{
+  InterpreterUnlocker loc;
+  PyObject* ob=getPyObj();
+  std::string s=convertPyObjectToString(ob);
+  Py_DECREF(ob);
+  return s;
+}
+
+
 //! Save the current data value for further reinitialization of the port
 /*!
  *
@@ -208,6 +250,21 @@ std::string InputCorbaPort::dump()
 //     }
 }
 
+std::string InputCorbaPort::valToStr()
+{
+  int isString = PyString_Check(getPyObj());
+  PyObject *strPyObj = PyObject_Str(getPyObj());
+  string val = PyString_AsString(strPyObj);
+  if (isString)
+    val = "\"" + val + "\"";
+  Py_DECREF(strPyObj);
+  return val;
+}
+
+void InputCorbaPort::valFromStr(std::string valstr)
+{
+}
+
 OutputCorbaPort::OutputCorbaPort(const std::string& name,
                                  Node *node,
                                  TypeCode * type)
@@ -340,6 +397,27 @@ CORBA::Any * OutputCorbaPort::getAnyOut()
   return a;
 }
 
+PyObject * OutputCorbaPort::getPyObj()
+{
+  CORBA::TypeCode_var tc=getAny()->type();
+  if (!tc->equivalent(CORBA::_tc_null))
+    return convertCorbaPyObject(edGetType(),getAny());
+  else
+    {
+      Py_INCREF(Py_None);
+      return Py_None;
+    }
+}
+
+std::string OutputCorbaPort::getAsString()
+{
+  InterpreterUnlocker loc;
+  PyObject* ob=getPyObj();
+  std::string s=convertPyObjectToString(ob);
+  Py_DECREF(ob);
+  return s;
+}
+
 std::string OutputCorbaPort::dump()
 {
   CORBA::TypeCode_var tc=_data.type();
@@ -360,3 +438,15 @@ namespace YACS {
   };
 };
 
+std::string OutputCorbaPort::valToStr()
+{
+  PyObject *strPyObj = PyObject_Str(getPyObj());
+  string val = PyString_AsString(strPyObj);
+  Py_DECREF(strPyObj);
+  return val;
+}
+
+void OutputCorbaPort::valFromStr(std::string valstr)
+{
+}
+