Version: 9.15.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::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)
 
void put (const char *data)
 
void releaseData () override
 
InputPortclone (Node *newHelder) const
 
virtual const char * getXml () const
 
void * get () const
 
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
 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...
 
bool canSafelySqueezeMemory () const
 
bool isBackLinked () const
 
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::DataPort
TypeCode_type
 
std::string _name
 
- Protected Attributes inherited from YACS::ENGINE::Port
Node_node
 
int _id
 
- Protected Attributes inherited from YACS::ENGINE::InPort
std::set< std::pair< OutPort *, bool > > _backLinks
 

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"
 
- Static Public Attributes inherited from YACS::ENGINE::DataFlowPort
static const char NAME [] ="DataFlowPort"
 
- Static Public Attributes inherited from YACS::ENGINE::DataPort
static const char NAME [] ="DataPort"
 
- 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)
 
void releaseDataUnsafe ()
 
- Protected Member Functions inherited from YACS::ENGINE::DataFlowPort
 DataFlowPort (const DataFlowPort &other, Node *newHelder)
 
 DataFlowPort (const std::string &name, Node *node, TypeCode *type)
 
- Protected Member Functions inherited from YACS::ENGINE::DataPort
virtual ~DataPort ()
 
 DataPort (const DataPort &other, Node *newHelder)
 
 DataPort (const std::string &name, Node *node, TypeCode *type)
 
- Protected Member Functions inherited from YACS::ENGINE::Port
 Port (Node *node)
 
 Port (const Port &other, Node *newHelder)
 
- Protected Member Functions inherited from YACS::ENGINE::InPort
 InPort (const InPort &other, Node *newHelder)
 
 InPort (const std::string &name, Node *node, TypeCode *type)
 
void edRemoveAllLinksLinkedWithMe ()
 
virtual void edNotifyReferencedBy (OutPort *fromPort, bool isLoopProof=true)
 
virtual void edNotifyDereferencedBy (OutPort *fromPort)
 
virtual void getAllRepresentants (std::set< InPort * > &repr) const
 
- 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

◆ InputStudyPort() [1/2]

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

Definition at line 275 of file StudyPorts.cxx.

276  : InputXmlPort(name, node, type),
277  DataPort(name, node, type),
278  Port(node)
279 {
280 }
DataPort(const DataPort &other, Node *newHelder)
Definition: DataPort.cxx:41
InputXmlPort(const std::string &name, Node *node, TypeCode *type)
Definition: XMLPorts.cxx:30
Port(Node *node)
Definition: Port.cxx:34

Referenced by clone().

◆ InputStudyPort() [2/2]

YACS::ENGINE::InputStudyPort::InputStudyPort ( const InputStudyPort other,
Node newHelder 
)

Definition at line 282 of file StudyPorts.cxx.

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

Member Function Documentation

◆ clone()

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

Implements YACS::ENGINE::InputPort.

Definition at line 289 of file StudyPorts.cxx.

290 {
291  return new InputStudyPort(*this,newHelder);
292 }
InputStudyPort(const std::string &name, Node *node, TypeCode *type)
Definition: StudyPorts.cxx:275

References InputStudyPort().

◆ dump()

std::string YACS::ENGINE::InputStudyPort::dump ( )
virtual

Reimplemented from YACS::ENGINE::InputXmlPort.

Definition at line 330 of file StudyPorts.cxx.

331 {
332  DEBTRACE( "InputStudyPort::dump " << _storeData );
333  DEBTRACE( "InputStudyPort::dump " << _data );
334  //return "<value><string>"+_storeData+"</string></value>";
335  return _data;
336 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

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

Referenced by putDataInStudy().

◆ getAsString()

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 341 of file StudyPorts.cxx.

342 {
343  return getData();
344 }

References getData().

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

◆ getData()

std::string YACS::ENGINE::InputStudyPort::getData ( )

◆ getIOR()

std::string YACS::ENGINE::InputStudyPort::getIOR ( )
virtual

Definition at line 307 of file StudyPorts.cxx.

308 {
309  switch(edGetType()->kind())
310  {
311  case Objref:
312  return splitXML(_data);
313  default:
314  return _data;
315  }
316 }
TypeCode * edGetType() const
Definition: DataPort.hxx:53
virtual std::string splitXML(const std::string &s)
Definition: StudyPorts.cxx:318

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

Referenced by putDataInStudy().

◆ getPyObj()

std::string YACS::ENGINE::InputStudyPort::getPyObj ( )
virtual

Definition at line 337 of file StudyPorts.cxx.

338 {
339  return getData();
340 }

References getData().

◆ putDataInStudy()

void YACS::ENGINE::InputStudyPort::putDataInStudy ( SALOMEDS::StudyBuilder_var  aBuilder)
virtual

Definition at line 346 of file StudyPorts.cxx.

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

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().

◆ setData()

void YACS::ENGINE::InputStudyPort::setData ( const std::string &  data)

Definition at line 294 of file StudyPorts.cxx.

295 {
296  _storeData = data;
297  DEBTRACE( "InputStudyPort::setData " << _storeData );
298  modified();
299 }
void modified()
Definition: Port.cxx:53

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

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

◆ splitXML()

std::string YACS::ENGINE::InputStudyPort::splitXML ( const std::string &  s)
virtual

Definition at line 318 of file StudyPorts.cxx.

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

Referenced by getIOR(), and putDataInStudy().

◆ typeName()

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

◆ _storeData

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: