+// 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"
#include <sstream>
#include <string>
#include <list>
+#include <stdlib.h>
//#define _DEVDEBUG_
#include "YacsTrace.hxx"
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);
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())
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();
}
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";
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())