1 // Copyright (C) 2006-2024 CEA, EDF
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_KernelServices.hxx"
29 #include "SALOMEDS.hh"
30 #include "SALOMEDS_Attributes.hh"
39 #include "YacsTrace.hxx"
46 const char StudyInNode::IMPL_NAME[]="XML";
48 StudyInNode::StudyInNode(const std::string& name)
51 _implementation=IMPL_NAME;
54 StudyInNode::StudyInNode(const StudyInNode& other, ComposedNode *father)
55 : DataNode(other, father)
59 Node *StudyInNode::simpleClone(ComposedNode *father, bool editionOnly) const
61 return new StudyInNode(*this,father);
64 OutputPort* StudyInNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
66 return new OutputStudyPort(outputPortName, this, type);
69 void StudyInNode::setData(OutputPort* port, const std::string& data)
71 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(port);
75 void StudyInNode::execute()
77 DEBTRACE("+++++++ StudyInNode::execute +++++++++++");
79 std::list<OutputPort *>::const_iterator iter;
80 for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
82 OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(*iter);
85 outp->getDataFromStudy();
89 _errorDetails=e.what();
93 DEBTRACE("+++++++ end StudyInNode::execute +++++++++++" );
96 void StudyInNode::checkBasicConsistency() const
98 DEBTRACE("StudyInNode::checkBasicConsistency");
99 if (! _setOfInputPort.empty())
101 std::string what = "StudyNode ";
103 what += " only accepts OutputStudyPort, no InputPort";
104 throw Exception(what);
107 std::list<OutputPort *>::const_iterator iter;
108 for(iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
110 OutputStudyPort *inp = dynamic_cast<OutputStudyPort*>(*iter);
113 std::string what("Output port: ");
114 what += (*iter)->getName();
115 what += " is not an OutputStudyPort. StudyNode ";
117 what += " only accepts OutputStudyPorts";
118 throw Exception(what);
121 std::string data = inp->getData();
125 std::string what("OutputStudyPort: ");
126 what += (*iter)->getName();
127 what += " is not initialised";
128 throw Exception(what);
133 void StudyInNode::accept(Visitor *visitor)
135 visitor->visitStudyInNode(this);
138 const char StudyOutNode::IMPL_NAME[]="XML";
140 StudyOutNode::StudyOutNode(const std::string& name)
143 _implementation=IMPL_NAME;
146 StudyOutNode::StudyOutNode(const StudyOutNode& other, ComposedNode *father)
147 : DataNode(other, father)
151 Node *StudyOutNode::simpleClone(ComposedNode *father, bool editionOnly) const
153 return new StudyOutNode(*this,father);
156 InputPort* StudyOutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
158 return new InputStudyPort(inputPortName, this, type);
161 void StudyOutNode::setData(InputPort* port, const std::string& data)
163 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(port);
168 SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::StudyBuilder_ptr builder,
169 SALOMEDS::SObject_ptr sobj, const std::string& name)
171 SALOMEDS::ChildIterator_var anIterator= KERNEL::getStudyServant()->NewChildIterator(sobj);
172 SALOMEDS::GenericAttribute_var anAttr;
173 SALOMEDS::AttributeName_var namAttr ;
174 SALOMEDS::SObject_var result=SALOMEDS::SObject::_nil();
176 for (; anIterator->More(); anIterator->Next())
178 SALOMEDS::SObject_var anObj=anIterator->Value();
179 if(anObj->FindAttribute(anAttr, "AttributeName"))
181 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
182 CORBA::String_var value=namAttr->Value();
183 if(name == (const char*)value)
190 if(CORBA::is_nil(result))
193 result = builder->NewObject( sobj );
194 anAttr=builder->FindOrCreateAttribute(result,"AttributeName");
195 namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
196 namAttr->SetValue(name.c_str());
198 return result._retn();
202 void StudyOutNode::execute()
204 DEBTRACE("+++++++ StudyOutNode::execute +++++++++++");
206 SALOMEDS::StudyBuilder_var aBuilder =KERNEL::getStudyServant()->NewBuilder() ;
207 if(CORBA::is_nil(aBuilder))
209 _errorDetails="Execution problem: can not create StudyBuilder";
210 throw Exception(_errorDetails);
213 SALOMEDS::GenericAttribute_var aGAttr;
214 SALOMEDS::SObject_var aSO ;
215 SALOMEDS::AttributeName_var anAttr ;
216 SALOMEDS::AttributeIOR_var iorAttr ;
218 std::list<InputPort *>::const_iterator iter;
219 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
221 InputStudyPort *inp = dynamic_cast<InputStudyPort *>(*iter);
222 inp->putDataInStudy(aBuilder);
225 // save in file if ref is given
228 KERNEL::getStudyServant()->SaveAs(Kernel_Utils::decode_s( _ref ), false, false);
230 DEBTRACE("+++++++ end StudyOutNode::execute +++++++++++" );
233 void StudyOutNode::checkBasicConsistency() const
235 DEBTRACE("StudyOutNode::checkBasicConsistency");
236 if (! _setOfOutputPort.empty())
238 std::string what = "StudyNode ";
240 what += " only accepts InputStudyPort, no OutputPort";
241 throw Exception(what);
244 std::list<InputPort *>::const_iterator iter;
245 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
247 InputStudyPort *inp = dynamic_cast<InputStudyPort*>(*iter);
250 std::string what("Input port: ");
251 what += (*iter)->getName();
252 what += " is not an InputStudyPort. StudyNode ";
254 what += " only accepts InputStudyPorts";
255 throw Exception(what);
257 inp->checkBasicConsistency();
259 std::string data = inp->getData();
263 std::string what("InputStudyPort: ");
264 what += (*iter)->getName();
265 what += " is not initialised";
266 throw Exception(what);
272 void StudyOutNode::accept(Visitor *visitor)
274 visitor->visitStudyOutNode(this);
277 } //end namespace ENGINE
278 } //end namespace YACS