Version: 8.3.0
YACS::ENGINE::InputStudyPort Class Reference

Class for Study input Ports. More...

#include <StudyPorts.hxx>

Inheritance diagram for YACS::ENGINE::InputStudyPort:
Collaboration diagram for YACS::ENGINE::InputStudyPort:

Public Member Functions

 InputStudyPort (const std::string &name, Node *node, TypeCode *type)
 
 InputStudyPort (const InputStudyPort &other, Node *newHelder)
 
InputPortclone (Node *newHelder) const
 
void setData (const std::string &data)
 
std::string getData ()
 
virtual std::string getIOR ()
 
virtual std::string splitXML (const std::string &s)
 
virtual std::string dump ()
 
virtual std::string getPyObj ()
 
virtual std::string getAsString ()
 returns port value as a string that can be used in a GUI for example More...
 
virtual std::string typeName ()
 
virtual void putDataInStudy (SALOMEDS::Study_var myStudy, SALOMEDS::StudyBuilder_var aBuilder)
 
- Public Member Functions inherited from YACS::ENGINE::InputXmlPort
 InputXmlPort (const std::string &name, Node *node, TypeCode *type)
 
 InputXmlPort (const InputXmlPort &other, Node *newHelder)
 
bool edIsManuallyInitialized () const
 Specifies if this port has been manually set by the call of InputPort::edInit. More...
 
void edRemoveManInit ()
 Removes eventually previous manual initialisation. More...
 
virtual void put (const void *data) throw (ConversionException)
 
void put (const char *data) throw (ConversionException)
 
InputPortclone (Node *newHelder) const
 
virtual const char * getXml () const
 
void * get () const throw (Exception)
 
bool isEmpty ()
 
virtual void exSaveInit ()
 Save the current data value for further reinitialization of the port. More...
 
virtual void exRestoreInit ()
 Restore the saved data value to current data value. More...
 
virtual std::string valToStr ()
 Gives a string representation of the data, for user interfaces. More...
 
virtual void valFromStr (std::string valstr)
 Allows to set data from a string representation used in user interface. More...
 
- Public Member Functions inherited from YACS::ENGINE::InputPort
virtual ~InputPort ()
 
std::string getNameOfTypeOfCurrentInstance () const
 
virtual InputPortgetPublicRepresentant ()
 returns the final physical port behind 'this'. More...
 
virtual bool isIntermediate () const
 
bool edIsInitialized () const
 soon deprecated More...
 
template<class T >
void edInit (T value)
 
void edInit (Any *value)
 
void edInit (const std::string &impl, const void *value)
 Initialize the port with an object (value) coming from a world with implementation impl. More...
 
virtual void checkBasicConsistency () const throw (Exception)
 Check basically that this port has one chance to be specified on time. It's a necessary condition not sufficient at all. More...
 
virtual void exInit (bool start)
 
virtual std::string getHumanRepr ()
 
virtual void setStringRef (std::string strRef)
 
bool canBeNull () const
 
- Public Member Functions inherited from YACS::ENGINE::DataFlowPort
TypeOfChannel getTypeOfChannel () const
 returns type of channel the port will use for data exchange on runtime : DATAFLOW or DATASTREAM. More...
 
virtual ~DataFlowPort ()
 
- Public Member Functions inherited from YACS::ENGINE::DataPort
TypeCodeedGetType () const
 
void edSetType (TypeCode *type)
 
std::string getName () const
 
void setName (std::string theName)
 
bool isDifferentTypeOf (const DataPort *other) const
 
- Public Member Functions inherited from YACS::ENGINE::Port
virtual ~Port ()
 
NodegetNode () const
 
int getNumId () const
 
void modified ()
 
- Public Member Functions inherited from YACS::ENGINE::InPort
virtual int edGetNumberOfLinks () const
 Returns number of physical backlinks NOT number of user backlinks. More...
 
virtual std::set< OutPort * > edSetOutPort () const
 Returns physical backlinks NOT user backlinks. More...
 
virtual ~InPort ()
 

Protected Attributes

std::string _storeData
 
- Protected Attributes inherited from YACS::ENGINE::InputXmlPort
std::string _data
 
std::string _initData
 
- Protected Attributes inherited from YACS::ENGINE::InputPort
Any_initValue
 
std::string _stringRef
 
bool _canBeNull
 
- Protected Attributes inherited from YACS::ENGINE::InPort
std::set< OutPort * > _backLinks
 
- Protected Attributes inherited from YACS::ENGINE::DataPort
TypeCode_type
 
std::string _name
 
- Protected Attributes inherited from YACS::ENGINE::Port
Node_node
 
int _id
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::ENGINE::DataPort
static DataPortisCrossingType (const std::vector< DataPort * > &historyOfLink)
 
- Static Public Attributes inherited from YACS::ENGINE::InputPort
static const char NAME [] ="InputPort"
 
- Protected Member Functions inherited from YACS::ENGINE::InputPort
 InputPort (const InputPort &other, Node *newHelder)
 
 InputPort (const std::string &name, Node *node, TypeCode *type, bool canBeNull=false)
 
- Static Protected Attributes inherited from YACS::ENGINE::Port
static int _total = 0
 
static const char NAME [] ="Port"
 

Detailed Description

Class for Study input Ports.

See Also
StudyOutNode

Definition at line 50 of file StudyPorts.hxx.

Constructor & Destructor Documentation

YACS::ENGINE::InputStudyPort::InputStudyPort ( const std::string &  name,
Node node,
TypeCode type 
)

Definition at line 274 of file StudyPorts.cxx.

Referenced by clone().

275  : InputXmlPort(name, node, type),
276  DataPort(name, node, type),
277  Port(node)
278 {
279 }
YACS::ENGINE::InputStudyPort::InputStudyPort ( const InputStudyPort other,
Node newHelder 
)

Definition at line 281 of file StudyPorts.cxx.

282  : InputXmlPort(other,newHelder),
283  DataPort(other,newHelder),
284  Port(other,newHelder),_storeData(other._storeData)
285 {
286 }

Member Function Documentation

InputPort * YACS::ENGINE::InputStudyPort::clone ( Node newHelder) const
virtual

Implements YACS::ENGINE::InputPort.

Definition at line 288 of file StudyPorts.cxx.

References InputStudyPort().

289 {
290  return new InputStudyPort(*this,newHelder);
291 }
std::string YACS::ENGINE::InputStudyPort::dump ( )
virtual

Reimplemented from YACS::ENGINE::InputXmlPort.

Definition at line 329 of file StudyPorts.cxx.

References YACS::ENGINE::InputXmlPort::_data, _storeData, and DEBTRACE.

Referenced by putDataInStudy().

330 {
331  DEBTRACE( "InputStudyPort::dump " << _storeData );
332  DEBTRACE( "InputStudyPort::dump " << _data );
333  //return "<value><string>"+_storeData+"</string></value>";
334  return _data;
335 }
std::string YACS::ENGINE::InputStudyPort::getAsString ( )
virtual

returns port value as a string that can be used in a GUI for example

Do nothing here. To subclass

Reimplemented from YACS::ENGINE::DataPort.

Definition at line 340 of file StudyPorts.cxx.

References getData().

Referenced by YACS::HMI::CommandSetInPortValue::localExecute(), and YACS::HMI::CommandSetInPortValue::localReverse().

341 {
342  return getData();
343 }
std::string YACS::ENGINE::InputStudyPort::getData ( )
std::string YACS::ENGINE::InputStudyPort::getIOR ( )
virtual

Definition at line 306 of file StudyPorts.cxx.

References YACS::ENGINE::InputXmlPort::_data, YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::Objref, and splitXML().

Referenced by putDataInStudy().

307 {
308  switch(edGetType()->kind())
309  {
310  case Objref:
311  return splitXML(_data);
312  default:
313  return _data;
314  }
315 }
std::string YACS::ENGINE::InputStudyPort::getPyObj ( )
virtual

Definition at line 336 of file StudyPorts.cxx.

References getData().

337 {
338  return getData();
339 }
void YACS::ENGINE::InputStudyPort::putDataInStudy ( SALOMEDS::Study_var  myStudy,
SALOMEDS::StudyBuilder_var  aBuilder 
)
virtual

Definition at line 345 of file StudyPorts.cxx.

References YACS::ENGINE::Bool, YACS::ENGINE::Proc::componentInstanceMap, DEBTRACE, YACS::ENGINE::Double, dump(), YACS::ENGINE::DataPort::edGetType(), YACS::ENGINE::findOrCreateSoWithName(), getData(), getIOR(), YACS::ENGINE::DataPort::getName(), YACS::ENGINE::Port::getNode(), YACS::ENGINE::RuntimeSALOME::getOrb(), YACS::ENGINE::Node::getProc(), YACS::ENGINE::getSALOMERuntime(), YACS::ENGINE::Int, YACS::ENGINE::Objref, orb, splitXML(), and YACS::ENGINE::String.

Referenced by YACS::ENGINE::StudyOutNode::execute().

346 {
347  SALOMEDS::GenericAttribute_var aGAttr;
348  SALOMEDS::SObject_var aSO ;
349  SALOMEDS::AttributeName_var anAttr ;
350  SALOMEDS::AttributeIOR_var iorAttr ;
351  SALOMEDS::SComponent_var aFather;
352 
353  std::string data = getData();
354  DEBTRACE("data: " << data );
355  //try to find an existing id (i:j:k...)
356  aSO = myStudy->FindObjectID(data.c_str());
357  if(CORBA::is_nil(aSO))
358  {
359  // the id does not exist. Try to create it by id
360  aSO=myStudy->CreateObjectID(data.c_str());
361  if(!CORBA::is_nil(aSO))
362  {
363  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeName");
364  anAttr = SALOMEDS::AttributeName::_narrow( aGAttr );
365  anAttr->SetValue(getName().c_str());
366  }
367  }
368 
369  if(CORBA::is_nil(aSO))
370  {
371  //try to publish the object with a given path
372  std::string name; // the component instance name
373  std::string objname; // the object name (eventually with "/")
374  std::string::size_type begin = data.find_first_not_of("/");
375  std::string::size_type pos=data.find_first_of("/", begin);
376  if (pos != std::string::npos)
377  {
378  name=data.substr(begin,pos-begin);
379  objname=data.substr(pos+1);
380  }
381  else
382  {
383  name=data.substr(begin);
384  objname="";
385  }
386  std::string pname="/"+name;
387  DEBTRACE(pname);
388  DEBTRACE(objname);
389 
390  Proc* proc=getNode()->getProc();
391  if(proc->componentInstanceMap.count(name)!=0)
392  {
393  // There is a component instance with this name. Is it a Salome component or not ?
394  ComponentInstance* compo=proc->componentInstanceMap[name];
395  if(SalomeComponent* scompo=dynamic_cast<SalomeComponent*>(compo))
396  {
397  //It's a Salome component, make it the right way : component name, component instance reference, ...
398  CORBA::Object_var compovar= scompo->getCompoPtr();
399  SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(compovar);
400  if ( !CORBA::is_nil( aDriver ) )
401  {
402  //It's a Salome component that implements the Driver interface. Use it to publish in study
403  CORBA::ORB_ptr orb;
404  CORBA::Object_var anObject;
405  try
406  {
407  orb = getSALOMERuntime()->getOrb();
408  anObject=orb->string_to_object(getIOR().c_str());
409  }
410  catch ( ... )
411  {
412  std::cerr << "Execution problem: can not get the object to publish" << std::endl;
413  return;
414  }
415  if ( aDriver->CanPublishInStudy( anObject ) )
416  {
417  //It's fine use the driver to publish
418  SALOMEDS::SObject_var aTmpSO; // initialized to nil
419  try
420  {
421  aTmpSO = aDriver->PublishInStudy(myStudy, aTmpSO, anObject,objname.c_str() );
422  return;
423  }
424  catch ( ... )
425  {
426  std::cerr << "Execution problem: error in PublishInStudy" << std::endl;
427  return;
428  }
429  }
430  }
431  }
432  }
433 
434  // Does component entry exist ?
435  aSO=myStudy->FindObjectByPath(pname.c_str());
436  if(CORBA::is_nil(aSO))
437  {
438  // We have not been able to publish the object with Salome Driver, make it the light way
439  aFather=aBuilder->NewComponent(name.c_str());
440  if(CORBA::is_nil(aFather))
441  {
442  std::cerr << "Execution problem: can not create component: " + name << std::endl;
443  return;
444  }
445  aGAttr=aBuilder->FindOrCreateAttribute(aFather,"AttributeName");
446  anAttr = SALOMEDS::AttributeName::_narrow( aGAttr );
447  anAttr->SetValue(name.c_str());
448  aSO=myStudy->FindObjectByPath(pname.c_str());
449  }
450 
451  begin=data.find_first_not_of("/",pos);
452  while (begin != std::string::npos)
453  {
454  pos = data.find_first_of("/", begin);
455  if (pos != std::string::npos)
456  name=data.substr(begin,pos-begin);
457  else
458  name=data.substr(begin);
459  aSO=findOrCreateSoWithName(myStudy,aBuilder,aSO,name);
460  begin=data.find_first_not_of("/",pos);
461  }
462  }
463 
464  if(CORBA::is_nil(aSO))
465  {
466  std::cerr << "Execution problem: can not create id or path: " + data + " in study" << std::endl;
467  return;
468  }
469 
470  std::string value;
471  SALOMEDS::AttributeComment_var commentAttr ;
472  SALOMEDS::AttributeReal_var realAttr ;
473  SALOMEDS::AttributeInteger_var intAttr ;
474  SALOMEDS::AttributeString_var stringAttr ;
475  double d;
476  long v;
477  switch(edGetType()->kind())
478  {
479  case Objref:
480  value=getIOR();
481  DEBTRACE(value);
482  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeIOR");
483  iorAttr = SALOMEDS::AttributeIOR::_narrow( aGAttr );
484  iorAttr->SetValue(value.c_str());
485  break;
486  case Double:
487  value=splitXML(dump());
488  DEBTRACE(value);
489  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeReal");
490  realAttr = SALOMEDS::AttributeReal::_narrow( aGAttr );
491  d=atof(value.c_str());
492  realAttr->SetValue(d);
493  break;
494  case Int:
495  value=splitXML(dump());
496  DEBTRACE(value);
497  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeInteger");
498  intAttr = SALOMEDS::AttributeInteger::_narrow( aGAttr );
499  v=atol(value.c_str());
500  intAttr->SetValue(v);
501  break;
502  case String:
503  case Bool:
504  value=splitXML(dump());
505  DEBTRACE(value);
506  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeComment");
507  commentAttr = SALOMEDS::AttributeComment::_narrow( aGAttr );
508  commentAttr->SetValue(value.c_str());
509  break;
510  default:
511  value=dump();
512  DEBTRACE(value);
513  aGAttr=aBuilder->FindOrCreateAttribute(aSO,"AttributeComment");
514  commentAttr = SALOMEDS::AttributeComment::_narrow( aGAttr );
515  commentAttr->SetValue(value.c_str());
516  }
517 }
void YACS::ENGINE::InputStudyPort::setData ( const std::string &  data)

Definition at line 293 of file StudyPorts.cxx.

References _storeData, DEBTRACE, and YACS::ENGINE::Port::modified().

Referenced by YACS::ENGINE::StudyOutNode::setData().

294 {
295  _storeData = data;
296  DEBTRACE( "InputStudyPort::setData " << _storeData );
297  modified();
298 }
std::string YACS::ENGINE::InputStudyPort::splitXML ( const std::string &  s)
virtual

Definition at line 317 of file StudyPorts.cxx.

Referenced by getIOR(), and putDataInStudy().

318 {
319  // <value><tag>content</tag></value>
320  std::string::size_type begin = s.find_first_of("<"); // <value>
321  begin = s.find_first_of(">",begin); // end of <value>
322  begin = s.find_first_of("<",begin); // beginning of <tag>
323  begin = s.find_first_of(">",begin); // end of <tag>
324  begin = s.find_first_not_of("> ",begin); // beginning of content
325  std::string::size_type last = s.find_first_of("<",begin); // beginning of </tag>
326  return s.substr(begin,last-begin);
327 }
virtual std::string YACS::ENGINE::InputStudyPort::typeName ( )
inlinevirtual

Reimplemented from YACS::ENGINE::InputPort.

Definition at line 63 of file StudyPorts.hxx.

63 {return "YACS__ENGINE__InputStudyPort";}

Member Data Documentation

std::string YACS::ENGINE::InputStudyPort::_storeData
protected

Definition at line 66 of file StudyPorts.hxx.

Referenced by dump(), getData(), and setData().


The documentation for this class was generated from the following files: