1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "RuntimeSALOME.hxx"
21 #include "StudyNodes.hxx"
22 #include "StudyPorts.hxx"
23 #include "Visitor.hxx"
24 #include "TypeCode.hxx"
25 #include "SalomeProc.hxx"
27 #include "SALOME_NamingService.hxx"
28 #include "SALOMEDS.hh"
29 #include "SALOMEDS_Attributes.hh"
38 #include "YacsTrace.hxx"
45 const char StudyInNode::IMPL_NAME[]="XML";
47 StudyInNode::StudyInNode(const std::string& name)
50 _implementation=IMPL_NAME;
53 StudyInNode::StudyInNode(const StudyInNode& other, ComposedNode *father)
54 : DataNode(other, father)
58 Node *StudyInNode::simpleClone(ComposedNode *father, bool editionOnly) const
60 return new StudyInNode(*this,father);
63 OutputPort* StudyInNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
65 return new OutputStudyPort(outputPortName, this, type);
68 void StudyInNode::setData(OutputPort* port, const std::string& data)
70 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(port);
74 void StudyInNode::execute()
76 DEBTRACE("+++++++ StudyInNode::execute +++++++++++");
77 SALOME_NamingService NS(getSALOMERuntime()->getOrb());
78 CORBA::Object_var obj=NS.Resolve("/Study");
79 if(CORBA::is_nil(obj))
81 _errorDetails="Execution problem: no naming service";
82 throw Exception(_errorDetails);
85 SALOMEDS::Study_var myStudy = SALOMEDS::Study::_narrow(obj);
86 if(CORBA::is_nil(myStudy))
88 _errorDetails="Execution problem: no study";
89 throw Exception(_errorDetails);
92 std::list<OutputPort *>::const_iterator iter;
93 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
95 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(*iter);
98 outp->getDataFromStudy(myStudy);
102 _errorDetails=e.what();
106 DEBTRACE("+++++++ end StudyInNode::execute +++++++++++" );
109 void StudyInNode::checkBasicConsistency() const throw(YACS::Exception)
111 DEBTRACE("StudyInNode::checkBasicConsistency");
112 if (! _setOfInputPort.empty())
114 std::string what = "StudyNode ";
116 what += " only accepts OutputStudyPort, no InputPort";
117 throw Exception(what);
120 std::list<OutputPort *>::const_iterator iter;
121 for(iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
123 OutputStudyPort *inp = dynamic_cast<OutputStudyPort*>(*iter);
126 std::string what("Output port: ");
127 what += (*iter)->getName();
128 what += " is not an OutputStudyPort. StudyNode ";
130 what += " only accepts OutputStudyPorts";
131 throw Exception(what);
134 std::string data = inp->getData();
138 std::string what("OutputStudyPort: ");
139 what += (*iter)->getName();
140 what += " is not initialised";
141 throw Exception(what);
146 void StudyInNode::accept(Visitor *visitor)
148 visitor->visitStudyInNode(this);
151 const char StudyOutNode::IMPL_NAME[]="XML";
153 StudyOutNode::StudyOutNode(const std::string& name)
156 _implementation=IMPL_NAME;
159 StudyOutNode::StudyOutNode(const StudyOutNode& other, ComposedNode *father)
160 : DataNode(other, father)
164 Node *StudyOutNode::simpleClone(ComposedNode *father, bool editionOnly) const
166 return new StudyOutNode(*this,father);
169 InputPort* StudyOutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
171 return new InputStudyPort(inputPortName, this, type);
174 void StudyOutNode::setData(InputPort* port, const std::string& data)
176 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(port);
181 SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::Study_ptr study, SALOMEDS::StudyBuilder_ptr builder,
182 SALOMEDS::SObject_ptr sobj, const std::string& name)
184 SALOMEDS::ChildIterator_var anIterator= study->NewChildIterator(sobj);
185 SALOMEDS::GenericAttribute_var anAttr;
186 SALOMEDS::AttributeName_var namAttr ;
187 SALOMEDS::SObject_var result=SALOMEDS::SObject::_nil();
189 for (; anIterator->More(); anIterator->Next())
191 SALOMEDS::SObject_var anObj=anIterator->Value();
192 if(anObj->FindAttribute(anAttr, "AttributeName"))
194 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
195 CORBA::String_var value=namAttr->Value();
196 if(name == (const char*)value)
203 if(CORBA::is_nil(result))
206 result = builder->NewObject( sobj );
207 anAttr=builder->FindOrCreateAttribute(result,"AttributeName");
208 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
209 namAttr->SetValue(name.c_str());
211 return result._retn();
215 void StudyOutNode::execute()
217 DEBTRACE("+++++++ StudyOutNode::execute +++++++++++");
218 SALOME_NamingService NS(getSALOMERuntime()->getOrb());
219 CORBA::Object_var obj=NS.Resolve("/Study");
220 if(CORBA::is_nil(obj))
222 _errorDetails="Execution problem: no naming service";
223 throw Exception(_errorDetails);
226 SALOMEDS::Study_var myStudy = SALOMEDS::Study::_narrow(obj);
227 if(CORBA::is_nil(myStudy))
229 _errorDetails="Execution problem: no study";
230 throw Exception(_errorDetails);
233 SALOMEDS::StudyBuilder_var aBuilder =myStudy->NewBuilder() ;
234 if(CORBA::is_nil(aBuilder))
236 _errorDetails="Execution problem: can not create StudyBuilder";
237 throw Exception(_errorDetails);
240 SALOMEDS::GenericAttribute_var aGAttr;
241 SALOMEDS::SObject_var aSO ;
242 SALOMEDS::AttributeName_var anAttr ;
243 SALOMEDS::AttributeIOR_var iorAttr ;
245 std::list<InputPort *>::const_iterator iter;
246 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
248 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(*iter);
249 inp->putDataInStudy(myStudy,aBuilder);
252 // save in file if ref is given
255 myStudy->SaveAs(_ref.c_str(), false, false);
257 DEBTRACE("+++++++ end StudyOutNode::execute +++++++++++" );
260 void StudyOutNode::checkBasicConsistency() const throw(YACS::Exception)
262 DEBTRACE("StudyOutNode::checkBasicConsistency");
263 if (! _setOfOutputPort.empty())
265 std::string what = "StudyNode ";
267 what += " only accepts InputStudyPort, no OutputPort";
268 throw Exception(what);
271 std::list<InputPort *>::const_iterator iter;
272 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
274 InputStudyPort *inp = dynamic_cast<InputStudyPort*>(*iter);
277 std::string what("Input port: ");
278 what += (*iter)->getName();
279 what += " is not an InputStudyPort. StudyNode ";
281 what += " only accepts InputStudyPorts";
282 throw Exception(what);
284 inp->checkBasicConsistency();
286 std::string data = inp->getData();
290 std::string what("InputStudyPort: ");
291 what += (*iter)->getName();
292 what += " is not initialised";
293 throw Exception(what);
299 void StudyOutNode::accept(Visitor *visitor)
301 visitor->visitStudyOutNode(this);
304 } //end namespace ENGINE
305 } //end namespace YACS