1 // Copyright (C) 2006-2020 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 "Basics_Utils.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include "SALOME_KernelServices.hxx"
30 #include "SALOMEDS.hh"
31 #include "SALOMEDS_Attributes.hh"
40 #include "YacsTrace.hxx"
47 const char StudyInNode::IMPL_NAME[]="XML";
49 StudyInNode::StudyInNode(const std::string& name)
52 _implementation=IMPL_NAME;
55 StudyInNode::StudyInNode(const StudyInNode& other, ComposedNode *father)
56 : DataNode(other, father)
60 Node *StudyInNode::simpleClone(ComposedNode *father, bool editionOnly) const
62 return new StudyInNode(*this,father);
65 OutputPort* StudyInNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
67 return new OutputStudyPort(outputPortName, this, type);
70 void StudyInNode::setData(OutputPort* port, const std::string& data)
72 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(port);
76 void StudyInNode::execute()
78 DEBTRACE("+++++++ StudyInNode::execute +++++++++++");
80 std::list<OutputPort *>::const_iterator iter;
81 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
83 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(*iter);
86 outp->getDataFromStudy();
90 _errorDetails=e.what();
94 DEBTRACE("+++++++ end StudyInNode::execute +++++++++++" );
97 void StudyInNode::checkBasicConsistency() const
99 DEBTRACE("StudyInNode::checkBasicConsistency");
100 if (! _setOfInputPort.empty())
102 std::string what = "StudyNode ";
104 what += " only accepts OutputStudyPort, no InputPort";
105 throw Exception(what);
108 std::list<OutputPort *>::const_iterator iter;
109 for(iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
111 OutputStudyPort *inp = dynamic_cast<OutputStudyPort*>(*iter);
114 std::string what("Output port: ");
115 what += (*iter)->getName();
116 what += " is not an OutputStudyPort. StudyNode ";
118 what += " only accepts OutputStudyPorts";
119 throw Exception(what);
122 std::string data = inp->getData();
126 std::string what("OutputStudyPort: ");
127 what += (*iter)->getName();
128 what += " is not initialised";
129 throw Exception(what);
134 void StudyInNode::accept(Visitor *visitor)
136 visitor->visitStudyInNode(this);
139 const char StudyOutNode::IMPL_NAME[]="XML";
141 StudyOutNode::StudyOutNode(const std::string& name)
144 _implementation=IMPL_NAME;
147 StudyOutNode::StudyOutNode(const StudyOutNode& other, ComposedNode *father)
148 : DataNode(other, father)
152 Node *StudyOutNode::simpleClone(ComposedNode *father, bool editionOnly) const
154 return new StudyOutNode(*this,father);
157 InputPort* StudyOutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
159 return new InputStudyPort(inputPortName, this, type);
162 void StudyOutNode::setData(InputPort* port, const std::string& data)
164 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(port);
169 SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::StudyBuilder_ptr builder,
170 SALOMEDS::SObject_ptr sobj, const std::string& name)
172 SALOMEDS::ChildIterator_var anIterator= KERNEL::getStudyServant()->NewChildIterator(sobj);
173 SALOMEDS::GenericAttribute_var anAttr;
174 SALOMEDS::AttributeName_var namAttr ;
175 SALOMEDS::SObject_var result=SALOMEDS::SObject::_nil();
177 for (; anIterator->More(); anIterator->Next())
179 SALOMEDS::SObject_var anObj=anIterator->Value();
180 if(anObj->FindAttribute(anAttr, "AttributeName"))
182 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
183 CORBA::String_var value=namAttr->Value();
184 if(name == (const char*)value)
191 if(CORBA::is_nil(result))
194 result = builder->NewObject( sobj );
195 anAttr=builder->FindOrCreateAttribute(result,"AttributeName");
196 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
197 namAttr->SetValue(name.c_str());
199 return result._retn();
203 void StudyOutNode::execute()
205 DEBTRACE("+++++++ StudyOutNode::execute +++++++++++");
207 SALOMEDS::StudyBuilder_var aBuilder =KERNEL::getStudyServant()->NewBuilder() ;
208 if(CORBA::is_nil(aBuilder))
210 _errorDetails="Execution problem: can not create StudyBuilder";
211 throw Exception(_errorDetails);
214 SALOMEDS::GenericAttribute_var aGAttr;
215 SALOMEDS::SObject_var aSO ;
216 SALOMEDS::AttributeName_var anAttr ;
217 SALOMEDS::AttributeIOR_var iorAttr ;
219 std::list<InputPort *>::const_iterator iter;
220 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
222 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(*iter);
223 inp->putDataInStudy(aBuilder);
226 // save in file if ref is given
229 KERNEL::getStudyServant()->SaveAs(Kernel_Utils::decode_s( _ref ), false, false);
231 DEBTRACE("+++++++ end StudyOutNode::execute +++++++++++" );
234 void StudyOutNode::checkBasicConsistency() const
236 DEBTRACE("StudyOutNode::checkBasicConsistency");
237 if (! _setOfOutputPort.empty())
239 std::string what = "StudyNode ";
241 what += " only accepts InputStudyPort, no OutputPort";
242 throw Exception(what);
245 std::list<InputPort *>::const_iterator iter;
246 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
248 InputStudyPort *inp = dynamic_cast<InputStudyPort*>(*iter);
251 std::string what("Input port: ");
252 what += (*iter)->getName();
253 what += " is not an InputStudyPort. StudyNode ";
255 what += " only accepts InputStudyPorts";
256 throw Exception(what);
258 inp->checkBasicConsistency();
260 std::string data = inp->getData();
264 std::string what("InputStudyPort: ");
265 what += (*iter)->getName();
266 what += " is not initialised";
267 throw Exception(what);
273 void StudyOutNode::accept(Visitor *visitor)
275 visitor->visitStudyOutNode(this);
278 } //end namespace ENGINE
279 } //end namespace YACS