]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/StudyNodes.cxx
Salome HOME
Return deleted code.
[modules/yacs.git] / src / runtime / StudyNodes.cxx
1 // Copyright (C) 2006-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "RuntimeSALOME.hxx"
21 #include "StudyNodes.hxx"
22 #include "StudyPorts.hxx"
23 #include "Visitor.hxx"
24 #include "TypeCode.hxx"
25 #include "SalomeProc.hxx"
26
27 #include "SALOME_NamingService.hxx"
28 #include "SALOMEDS.hh"
29 #include "SALOMEDS_Attributes.hh"
30
31 #include <iostream>
32 #include <sstream>
33 #include <string>
34 #include <list>
35 #include <stdlib.h>
36
37 //#define _DEVDEBUG_
38 #include "YacsTrace.hxx"
39
40 namespace YACS
41 {
42 namespace ENGINE
43 {
44
45 const char StudyInNode::IMPL_NAME[]="XML";
46
47 StudyInNode::StudyInNode(const std::string& name)
48   : DataNode(name)
49 {
50   _implementation=IMPL_NAME;
51 }
52
53 StudyInNode::StudyInNode(const StudyInNode& other, ComposedNode *father)
54   : DataNode(other, father)
55 {
56 }
57
58 Node *StudyInNode::simpleClone(ComposedNode *father, bool editionOnly) const
59 {
60   return new StudyInNode(*this,father);
61 }
62
63 OutputPort* StudyInNode::createOutputPort(const std::string& outputPortName, TypeCode* type)
64 {
65   return new OutputStudyPort(outputPortName, this, type);
66 }
67
68 void StudyInNode::setData(OutputPort* port, const std::string& data)
69 {
70   OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(port);
71   outp->setData(data);
72 }
73
74 void StudyInNode::execute()
75 {
76   DEBTRACE("+++++++ StudyInNode::execute +++++++++++");
77   SALOME_NamingService NS(getSALOMERuntime()->getOrb());
78   CORBA::Object_var obj=NS.Resolve("/Study");
79   if(CORBA::is_nil(obj)) 
80     {
81       _errorDetails="Execution problem: no naming service";
82       throw Exception(_errorDetails);
83     }
84
85   SALOMEDS::Study_var myStudy = SALOMEDS::Study::_narrow(obj);
86   if(CORBA::is_nil(myStudy)) 
87     {
88       _errorDetails="Execution problem: no study";
89       throw Exception(_errorDetails);
90     }
91
92   std::list<OutputPort *>::const_iterator iter;
93   for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++)
94     {
95       OutputStudyPort *outp = dynamic_cast<OutputStudyPort *>(*iter);
96       try
97         {
98           outp->getDataFromStudy(myStudy);
99         }
100       catch(Exception& e)
101         {
102           _errorDetails=e.what();
103           throw;
104         }
105     }
106   DEBTRACE("+++++++ end StudyInNode::execute +++++++++++" );
107 }
108
109 void StudyInNode::checkBasicConsistency() const throw(YACS::Exception)
110 {
111   DEBTRACE("StudyInNode::checkBasicConsistency");
112   if (! _setOfInputPort.empty())
113     {
114       std::string what = "StudyNode ";
115       what += getName();
116       what += " only accepts OutputStudyPort, no InputPort";
117       throw Exception(what);
118     }
119
120   std::list<OutputPort *>::const_iterator iter;
121   for(iter=_setOfOutputPort.begin();iter!=_setOfOutputPort.end();iter++)
122     {
123       OutputStudyPort *inp = dynamic_cast<OutputStudyPort*>(*iter);
124       if (!inp)
125         {
126           std::string what("Output port: ");
127           what += (*iter)->getName();
128           what += " is not an OutputStudyPort. StudyNode ";
129           what += getName();
130           what += " only accepts OutputStudyPorts";
131           throw Exception(what);
132         }
133
134       std::string data = inp->getData();
135       DEBTRACE(data);
136       if (data.empty())
137         {
138           std::string what("OutputStudyPort: ");
139           what += (*iter)->getName();
140           what += " is not initialised";
141           throw Exception(what);
142         }
143     }
144 }
145
146 void StudyInNode::accept(Visitor *visitor)
147 {
148   visitor->visitStudyInNode(this);
149 }
150
151 const char StudyOutNode::IMPL_NAME[]="XML";
152
153 StudyOutNode::StudyOutNode(const std::string& name)
154   : DataNode(name)
155 {
156   _implementation=IMPL_NAME;
157 }
158
159 StudyOutNode::StudyOutNode(const StudyOutNode& other, ComposedNode *father)
160   : DataNode(other, father)
161 {
162 }
163
164 Node *StudyOutNode::simpleClone(ComposedNode *father, bool editionOnly) const
165 {
166   return new StudyOutNode(*this,father);
167 }
168
169 InputPort* StudyOutNode::createInputPort(const std::string& inputPortName, TypeCode* type)
170 {
171   return new InputStudyPort(inputPortName, this, type);
172 }
173
174 void StudyOutNode::setData(InputPort* port, const std::string& data)
175 {
176   InputStudyPort *inp = dynamic_cast<InputStudyPort *>(port);
177   inp->setData(data);
178 }
179
180 /*
181 SALOMEDS::SObject_ptr findOrCreateSoWithName(SALOMEDS::Study_ptr study, SALOMEDS::StudyBuilder_ptr builder,
182                                              SALOMEDS::SObject_ptr sobj, const std::string& name)
183 {
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();
188
189   for (; anIterator->More(); anIterator->Next())
190     {
191       SALOMEDS::SObject_var anObj=anIterator->Value();
192       if(anObj->FindAttribute(anAttr, "AttributeName"))
193         {
194           namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
195           CORBA::String_var value=namAttr->Value();
196           if(name == (const char*)value)
197             {
198               result=anObj;
199               break;
200             }
201         }
202     }
203   if(CORBA::is_nil(result))
204     {
205       //create it
206       result = builder->NewObject( sobj );
207       anAttr=builder->FindOrCreateAttribute(result,"AttributeName");
208       namAttr = SALOMEDS::AttributeName::_narrow( anAttr );
209       namAttr->SetValue(name.c_str());
210     }
211   return result._retn();
212 }
213 */
214
215 void StudyOutNode::execute()
216 {
217   DEBTRACE("+++++++ StudyOutNode::execute +++++++++++");
218   SALOME_NamingService NS(getSALOMERuntime()->getOrb());
219   CORBA::Object_var obj=NS.Resolve("/Study");
220   if(CORBA::is_nil(obj))
221     {
222       _errorDetails="Execution problem: no naming service";
223       throw Exception(_errorDetails);
224     }
225
226   SALOMEDS::Study_var myStudy = SALOMEDS::Study::_narrow(obj);
227   if(CORBA::is_nil(myStudy))
228     {
229       _errorDetails="Execution problem: no study";
230       throw Exception(_errorDetails);
231     }
232
233   SALOMEDS::StudyBuilder_var aBuilder =myStudy->NewBuilder() ;
234   if(CORBA::is_nil(aBuilder))
235     {
236       _errorDetails="Execution problem: can not create StudyBuilder";
237       throw Exception(_errorDetails);
238     }
239
240   SALOMEDS::GenericAttribute_var aGAttr;
241   SALOMEDS::SObject_var aSO ;
242   SALOMEDS::AttributeName_var anAttr ;
243   SALOMEDS::AttributeIOR_var iorAttr ;
244
245   std::list<InputPort *>::const_iterator iter;
246   for(iter = _setOfInputPort.begin(); iter != _setOfInputPort.end(); iter++)
247     {
248       InputStudyPort *inp = dynamic_cast<InputStudyPort *>(*iter);
249       inp->putDataInStudy(myStudy,aBuilder);
250     }
251
252   // save in file if ref is given
253   if(_ref != "")
254     {
255           myStudy->SaveAs(_ref.c_str(), false, false);
256     }
257   DEBTRACE("+++++++ end StudyOutNode::execute +++++++++++" );
258 }
259
260 void StudyOutNode::checkBasicConsistency() const throw(YACS::Exception)
261 {
262   DEBTRACE("StudyOutNode::checkBasicConsistency");
263   if (! _setOfOutputPort.empty())
264     {
265       std::string what = "StudyNode ";
266       what += getName();
267       what += " only accepts InputStudyPort, no OutputPort";
268       throw Exception(what);
269     }
270
271   std::list<InputPort *>::const_iterator iter;
272   for(iter=_setOfInputPort.begin();iter!=_setOfInputPort.end();iter++)
273     {
274       InputStudyPort *inp = dynamic_cast<InputStudyPort*>(*iter);
275       if (!inp)
276         {
277           std::string what("Input port: ");
278           what += (*iter)->getName();
279           what += " is not an InputStudyPort. StudyNode ";
280           what += getName();
281           what += " only accepts InputStudyPorts";
282           throw Exception(what);
283         }
284       inp->checkBasicConsistency();
285
286       std::string data = inp->getData();
287       DEBTRACE(data);
288       if (data.empty())
289         {
290           std::string what("InputStudyPort: ");
291           what += (*iter)->getName();
292           what += " is not initialised";
293           throw Exception(what);
294         }
295     }
296
297 }
298
299 void StudyOutNode::accept(Visitor *visitor)
300 {
301   visitor->visitStudyOutNode(this);
302 }
303
304 } //end namespace ENGINE
305 } //end namespace YACS