]> SALOME platform Git repositories - modules/yacs.git/blobdiff - src/runtime/StudyNodes.cxx
Salome HOME
Merge Python 3 porting.
[modules/yacs.git] / src / runtime / StudyNodes.cxx
index 9a9a23f12c6035d4bf5e90f93ea2968dc3379103..0d9349030e2009b57714f0ae9268de87a99016c0 100644 (file)
@@ -1,9 +1,32 @@
+// Copyright (C) 2006-2016  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, or (at your option) any later version.
+//
+// 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
+//
+
 #include "RuntimeSALOME.hxx"
 #include "StudyNodes.hxx"
 #include "StudyPorts.hxx"
 #include "Visitor.hxx"
+#include "TypeCode.hxx"
+#include "SalomeProc.hxx"
 
+#include "Basics_Utils.hxx"
 #include "SALOME_NamingService.hxx"
+#include "SALOME_KernelServices.hxx"
 #include "SALOMEDS.hh"
 #include "SALOMEDS_Attributes.hh"
 
@@ -11,6 +34,7 @@
 #include <sstream>
 #include <string>
 #include <list>
+#include <stdlib.h>
 
 //#define _DEVDEBUG_
 #include "YacsTrace.hxx"
@@ -43,7 +67,7 @@ OutputPort* StudyInNode::createOutputPort(const std::string& outputPortName, Typ
   return new OutputStudyPort(outputPortName, this, type);
 }
 
-void StudyInNode::setData(OutputPort* port, std::string& data)
+void StudyInNode::setData(OutputPort* port, const std::string& data)
 {
   OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(port);
   outp->setData(data);
@@ -52,83 +76,25 @@ void StudyInNode::setData(OutputPort* port, std::string& data)
 void StudyInNode::execute()
 {
   DEBTRACE("+++++++ StudyInNode::execute +++++++++++");
-  SALOME_NamingService NS(getSALOMERuntime()->getOrb());
-  CORBA::Object_var obj=NS.Resolve("/myStudyManager");
-  if(CORBA::is_nil(obj)) 
-    {
-      _errorDetails="Execution problem: no naming service";
-      throw Exception(_errorDetails);
-    }
-
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(obj);
-  if(CORBA::is_nil(aStudyManager)) 
-    {
-      _errorDetails="Execution problem: no naming service";
-      throw Exception(_errorDetails);
-    }
-
-  int studyid=1;
-  if (_propertyMap.find("StudyID") != _propertyMap.end())
-    {
-      // StudyId is specified
-      studyid=atoi(_propertyMap["StudyID"].c_str());
-    }
-
-  SALOMEDS::Study_var myStudy =aStudyManager->GetStudyByID(studyid);
-  if(CORBA::is_nil(myStudy)) 
-    {
-      std::stringstream msg;
-      msg << "Execution problem: no study with id " << studyid;
-      _errorDetails=msg.str();
-      throw Exception(_errorDetails);
-    }
 
   std::list<OutputPort *>::const_iterator iter;
   for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
     {
       OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(*iter);
-      std::string data = outp->getData();
-      DEBTRACE("data: " << data );
-      //try an id
-      SALOMEDS::SObject_var aSO = myStudy->FindObjectID(data.c_str());
-      if(CORBA::is_nil(aSO)) 
+      try
         {
-          //try a path
-          aSO=myStudy->FindObjectByPath(data.c_str());
-          if(CORBA::is_nil(aSO)) 
-            {
-              _errorDetails="Execution problem: no id or path: ";
-              _errorDetails=_errorDetails+data+" in study";
-              throw Exception(_errorDetails);
-            }
+          outp->getDataFromStudy();
         }
-
-      CORBA::String_var path=myStudy->GetObjectPath(aSO);
-      DEBTRACE(path);
-      CORBA::String_var id=aSO->GetID();
-      DEBTRACE(id);
-      //CORBA::Object_var sobj=aSO->GetObject();
-      SALOMEDS::GenericAttribute_var aGAttr;
-
-      CORBA::String_var value;
-      if ( aSO->FindAttribute( aGAttr, "AttributeIOR" ) )
+      catch(Exception& e)
         {
-          SALOMEDS::AttributeIOR_var anAttr = SALOMEDS::AttributeIOR::_narrow( aGAttr );
-          value=anAttr->Value();
+          _errorDetails=e.what();
+          throw;
         }
-      else
-        {
-          //Problem !!!
-          _errorDetails="Execution problem: no AttributeIOR in study object: ";
-          _errorDetails=_errorDetails+data;
-          throw Exception(_errorDetails);
-        }
-      outp->putIOR((const char*)value);
     }
   DEBTRACE("+++++++ end StudyInNode::execute +++++++++++" );
 }
 
-void StudyInNode::checkBasicConsistency() const throw(Exception)
+void StudyInNode::checkBasicConsistency() const throw(YACS::Exception)
 {
   DEBTRACE("StudyInNode::checkBasicConsistency");
   if (! _setOfInputPort.empty())
@@ -193,16 +159,17 @@ InputPort* StudyOutNode::createInputPort(const std::string& inputPortName, TypeC
   return new InputStudyPort(inputPortName, this, type);
 }
 
-void StudyOutNode::setData(InputPort* port, std::string& data)
+void StudyOutNode::setData(InputPort* port, const std::string& data)
 {
   InputStudyPort *inp = dynamic_cast<InputStudyPort *>(port);
   inp->setData(data);
 }
 
-SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::Study_ptr study, SALOMEDS::StudyBuilder_ptr builder,
+/*
+SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::StudyBuilder_ptr builder,
                                              SALOMEDS::SObject_ptr sobj, const std::string& name)
 {
-  SALOMEDS::ChildIterator_var anIterator= study->NewChildIterator(sobj);
+  SALOMEDS::ChildIterator_var anIterator= KERNEL::getStudyServant()->NewChildIterator(sobj);
   SALOMEDS::GenericAttribute_var anAttr;
   SALOMEDS::AttributeName_var namAttr ;
   SALOMEDS::SObject_var result=SALOMEDS::SObject::_nil();
@@ -231,48 +198,13 @@ SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::Study_ptr study, SALOMEDS
     }
   return result._retn();
 }
+*/
 
 void StudyOutNode::execute()
 {
   DEBTRACE("+++++++ StudyOutNode::execute +++++++++++");
-  SALOME_NamingService NS(getSALOMERuntime()->getOrb());
-  CORBA::Object_var obj=NS.Resolve("/myStudyManager");
-  if(CORBA::is_nil(obj))
-    {
-      _errorDetails="Execution problem: no naming service";
-      throw Exception(_errorDetails);
-    }
 
-  SALOMEDS::StudyManager_var aStudyManager = SALOMEDS::StudyManager::_narrow(obj);
-  if(CORBA::is_nil(aStudyManager))
-    {
-      _errorDetails="Execution problem: no naming service";
-      throw Exception(_errorDetails);
-    }
-
-  int studyid=1;
-  if (_propertyMap.find("StudyID") != _propertyMap.end())
-    {
-      // StudyId is specified
-      studyid=atoi(_propertyMap["StudyID"].c_str());
-    }
-
-  SALOMEDS::Study_var myStudy =aStudyManager->GetStudyByID(studyid);
-  if(CORBA::is_nil(myStudy))
-    {
-      //open a new one
-      std::stringstream msg;
-      msg << "Study" << studyid;
-      myStudy=aStudyManager->NewStudy(msg.str().c_str());
-      if(CORBA::is_nil(myStudy))
-        {
-          _errorDetails="Execution problem: can not create new study " + msg.str();
-          throw Exception(_errorDetails);
-        }
-    }
-  DEBTRACE(myStudy->StudyId());
-
-  SALOMEDS::StudyBuilder_var aBuilder =myStudy->NewBuilder() ;
+  SALOMEDS::StudyBuilder_var aBuilder =KERNEL::getStudyServant()->NewBuilder() ;
   if(CORBA::is_nil(aBuilder))
     {
       _errorDetails="Execution problem: can not create StudyBuilder";
@@ -288,86 +220,18 @@ void StudyOutNode::execute()
   for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
     {
       InputStudyPort *inp = dynamic_cast<InputStudyPort *>(*iter);
-      std::string data = inp->getData();
-      DEBTRACE("data: " << data );
-      //try to find an id
-      aSO = myStudy->FindObjectID(data.c_str());
-      if(CORBA::is_nil(aSO)) 
-        {
-          // the id does not exist. Try to create it by id
-          aSO=myStudy->CreateObjectID(data.c_str());
-          if(!CORBA::is_nil(aSO)) 
-            {
-              aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeName");
-              anAttr = SALOMEDS::AttributeName::_narrow( aGAttr );
-              anAttr->SetValue(inp->getName().c_str());
-            }
-        }
-      if(CORBA::is_nil(aSO)) 
-        {
-          // try a path
-          aSO=myStudy->FindObjectByPath(data.c_str());
-        }
-      if(CORBA::is_nil(aSO)) 
-        {
-          //try to create it by path
-          std::string name;
-          std::string::size_type begin = data.find_first_not_of("/");
-          std::string::size_type pos=data.find_first_of("/", begin);
-          if (pos != std::string::npos)
-            name=data.substr(begin,pos-begin);
-          else
-            name=data.substr(begin);
-          name="/"+name;
-          DEBTRACE(name);
-          aSO=myStudy->FindObjectByPath(name.c_str());
-          if(CORBA::is_nil(aSO)) 
-            {
-              DEBTRACE("Create an entry " << name);
-              //create a container component
-              aSO=aBuilder->NewComponent(name.c_str());
-              if(CORBA::is_nil(aSO)) 
-                {
-                  std::cerr << "Execution problem: can not create component: " + data << std::endl;
-                  continue;
-                }
-              aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeIOR");
-              iorAttr = SALOMEDS::AttributeIOR::_narrow( aGAttr );
-              iorAttr->SetValue(name.c_str());
-            }
-          begin=data.find_first_not_of("/",pos);
-          while (begin != std::string::npos)
-            {
-              pos = data.find_first_of("/", begin);
-              if (pos != std::string::npos)
-                name=data.substr(begin,pos-begin);
-              else
-                name=data.substr(begin);
-              aSO=findOrCreateSoWithName(myStudy,aBuilder,aSO,name);
-              begin=data.find_first_not_of("/",pos);
-            }
-        }
-      if(CORBA::is_nil(aSO)) 
-        {
-          std::cerr << "Execution problem: can not create id or path: " + data + " in study" << std::endl;
-          continue;
-        }
-      std::string value=inp->getIOR();
-      DEBTRACE(value);
-      aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeIOR");
-      iorAttr = SALOMEDS::AttributeIOR::_narrow( aGAttr );
-      iorAttr->SetValue(value.c_str());
+      inp->putDataInStudy(aBuilder);
     }
 
   // save in file if ref is given
   if(_ref != "")
     {
-      aStudyManager->SaveAs(_ref.c_str(),myStudy, false);
+      KERNEL::getStudyServant()->SaveAs(Kernel_Utils::decode_s( _ref ), false, false);
     }
   DEBTRACE("+++++++ end StudyOutNode::execute +++++++++++" );
 }
 
-void StudyOutNode::checkBasicConsistency() const throw(Exception)
+void StudyOutNode::checkBasicConsistency() const throw(YACS::Exception)
 {
   DEBTRACE("StudyOutNode::checkBasicConsistency");
   if (! _setOfOutputPort.empty())