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 "PresetPorts.hxx"
21 #include "OutNode.hxx"
22 #include "Visitor.hxx"
30 #include "YacsTrace.hxx"
39 /*! \class YACS::ENGINE::OutNode
40 * \brief Class for data out node
45 const char OutNode::IMPL_NAME[]="XML";
47 OutNode::OutNode(const std::string& name)
50 _implementation=IMPL_NAME;
53 OutNode::OutNode(const OutNode& other, ComposedNode *father)
54 : DataNode(other, father)
58 InputPort* OutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
60 return new InputPresetPort(inputPortName, this, type);
63 void OutNode::dump(std::ostream &out)
65 std::list<InputPort *>::const_iterator iter;
66 for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
68 InputPresetPort *inp = dynamic_cast<InputPresetPort *>(*iter);
69 if(inp->getData() != "")
71 //save the file in the given reference
72 std::string xmlValue=inp->dump();
73 std::string::size_type i=xmlValue.find_first_of('/',0);
74 xmlValue=xmlValue.substr(i);
75 i=xmlValue.find_first_of('<',0);
76 std::ifstream fin(xmlValue.substr(0,i).c_str());
77 std::ofstream fout(inp->getData().c_str());
78 fout << fin.rdbuf(); // Dumps file contents to file
79 out << "<value><objref>" << inp->getData() << "</objref></value>" << std::endl;
82 out << inp->dump() << std::endl;
86 void OutNode::execute()
88 DEBTRACE("+++++++ OutNode::execute +++++++++++");
91 std::ofstream out(_ref.c_str());
96 DEBTRACE("+++++++ end OutNode::execute +++++++++++" );
99 void OutNode::accept(Visitor *visitor)
101 visitor->visitOutNode(this);
104 void OutNode::setData(InputPort* port, const std::string& data)
106 InputPresetPort *inp = dynamic_cast<InputPresetPort *>(port);
110 void OutNode::checkBasicConsistency() const
112 DEBTRACE("OutNode::checkBasicConsistency");
113 if (! _setOfOutputPort.empty())
115 string what = "OutNode ";
117 what += " only accepts InputPorts, no OutputPorts";
118 throw Exception(what);
120 list<InputPort *>::const_iterator iter;
121 for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
123 InputPresetPort *preset = dynamic_cast<InputPresetPort*>(*iter);
126 string what("Input port: ");
127 what += (*iter)->getName();
128 what += " is not an InputPresetPort. PresetNode ";
130 what += " only accepts InputPresetPorts";
131 throw Exception(what);
133 preset->checkBasicConsistency();
138 Node *OutNode::simpleClone(ComposedNode *father, bool editionOnly) const
140 return new OutNode(*this,father);