Version: 9.15.0
YACS::HMI::CommandAddLink Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandAddLink:
Collaboration diagram for YACS::HMI::CommandAddLink:

Public Member Functions

 CommandAddLink (std::string outNode, std::string outPort, TypeOfElem outPortType, std::string inNode, std::string inPort, TypeOfElem inPortType, bool control=true)
 
- Public Member Functions inherited from YACS::HMI::Command
 Command ()
 
virtual bool execute ()
 the command is executed a first time after its registration for undo redo, then on redo More...
 
virtual bool reverse (bool isNormal=true)
 Reverse action: undo. More...
 
virtual bool executeSubOnly ()
 execute only sub commands in a reverse action More...
 
std::string recursiveDump (int level=0)
 
void addSubCommand (Command *command)
 
bool isNormalReverse ()
 

Protected Member Functions

virtual bool localExecute ()
 
virtual bool localReverse ()
 
virtual std::string dump ()
 

Protected Attributes

std::string _outNode
 
std::string _outPort
 
TypeOfElem _outPortType
 
std::string _inNode
 
std::string _inPort
 
TypeOfElem _inPortType
 
bool _control
 
bool _controlCreatedWithDF
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 499 of file commandsProc.hxx.

Constructor & Destructor Documentation

◆ CommandAddLink()

CommandAddLink::CommandAddLink ( std::string  outNode,
std::string  outPort,
TypeOfElem  outPortType,
std::string  inNode,
std::string  inPort,
TypeOfElem  inPortType,
bool  control = true 
)

Definition at line 2857 of file commandsProc.cxx.

2859  : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2860  _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2861 {
2862  DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2863  _controlCreatedWithDF = false;
2864 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _controlCreatedWithDF, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandAddLink::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2866 of file commandsProc.cxx.

2867 {
2868  string s = "false";
2869  if (_control) s = "true";
2870  string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2871  return ret;
2872 }

References _control, _inNode, _inPort, _outNode, and _outPort.

◆ localExecute()

bool CommandAddLink::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2874 of file commandsProc.cxx.

2875 {
2876  DEBTRACE("CommandAddLink::localExecute");
2877  DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2878  try
2879  {
2880  Proc* proc = GuiContext::getCurrent()->getProc();
2881  Node* outn = proc->getChildByName(_outNode);
2882  Node* inn = proc->getChildByName(_inNode);
2883  OutPort* outp;
2884  InPort* inp;
2885 
2886  // --- is a control link already existing ?
2887  bool preexistingControl = false;
2888  {
2889  Node* outn2=outn;
2890  Node* inn2=inn;
2891  ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2892  if(outn2==father || inn2==father)
2893  preexistingControl = true;
2894  else
2895  {
2896  while(outn2->getFather() != father)
2897  outn2 = outn2->getFather();
2898  while(inn2->getFather() != father)
2899  inn2 = inn2->getFather();
2900  OutGate *ogate = outn2->getOutGate();
2901  InGate *igate = inn2->getInGate();
2902  if (ogate->isAlreadyInSet(igate))
2903  preexistingControl = true;
2904  }
2905  }
2906 
2907  if(_outPortType == OUTPUTPORT)
2908  outp = outn->getOutputPort(_outPort);
2909  else
2910  outp = outn->getOutputDataStreamPort(_outPort);
2911 
2912  if(_inPortType == INPUTPORT)
2913  inp = inn->getInputPort(_inPort);
2914  else
2915  inp = inn->getInputDataStreamPort(_inPort);
2916 
2917  ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2918  DEBTRACE(cla->getName());
2919  if (dynamic_cast<OutputDataStreamPort*>(outp))
2920  cla->edAddLink(outp,inp);
2921  else if(_control)
2922  cla->edAddDFLink(outp,inp);
2923  else
2924  cla->edAddLink(outp,inp);
2925 
2926  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2928  SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2929  DEBTRACE(scla->getName());
2934  SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2935 
2936  // --- if control link, identify the nodes linked and draw the control link if not already existing
2937 
2938  if (_control)
2939  {
2940  ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2941  if(outn==father || inn==father) return true;
2942  while(outn->getFather() != father)
2943  outn = outn->getFather();
2944  while(inn->getFather() != father)
2945  inn = inn->getFather();
2946  OutGate *ogate = outn->getOutGate();
2947  InGate *igate = inn->getInGate();
2948  if (ogate->isAlreadyInSet(igate))
2949  {
2950  if (!preexistingControl)
2951  _controlCreatedWithDF = true;
2952  pair<Node*,Node*> keyLink(outn,inn);
2953  if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2954  {
2957  if (!sfno || !sfni) return true;
2958  SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2959  }
2960  }
2961  }
2962  return true;
2963  }
2964  catch (Exception& ex)
2965  {
2966  DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2967  setErrorMsg(ex);
2968  return false;
2969  }
2970 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
Base class for all composed nodes.
Node * getChildByName(const std::string &name) const
std::string getName() const
virtual bool edAddDFLink(OutPort *start, InPort *end)
Connect an OutPort to an InPort and add the necessary control link.
bool edAddLink(OutPort *start, InPort *end)
Add a dataflow link between two data ports.
Base class for all nodes.
Definition: Node.hxx:70
virtual InputDataStreamPort * getInputDataStreamPort(const std::string &name) const =0
OutGate * getOutGate()
Definition: Node.hxx:124
ComposedNode * getFather() const
Definition: Node.hxx:127
InGate * getInGate()
Definition: Node.hxx:123
virtual InputPort * getInputPort(const std::string &name) const
Definition: Node.cxx:260
virtual OutputPort * getOutputPort(const std::string &name) const =0
virtual OutputDataStreamPort * getOutputDataStreamPort(const std::string &name) const =0
bool isAlreadyInSet(InGate *inGate) const
Definition: OutGate.cxx:150
Base class for all schema objects.
Definition: Proc.hxx:44
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
std::map< YACS::ENGINE::DataPort *, YACS::HMI::SubjectDataPort * > _mapOfSubjectDataPort
Definition: guiContext.hxx:71
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:68
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
SubjectControlLink * addSubjectControlLink(SubjectNode *sno, SubjectNode *sni)
SubjectLink * addSubjectLink(SubjectNode *sno, SubjectDataPort *spo, SubjectNode *sni, SubjectDataPort *spi)
virtual std::string getName()
void setErrorMsg(YACS::Exception &ex)

References _control, _controlCreatedWithDF, _inNode, _inPort, _inPortType, YACS::HMI::GuiContext::_mapOfSubjectDataPort, YACS::HMI::GuiContext::_mapOfSubjectNode, _outNode, _outPort, _outPortType, YACS::HMI::SubjectComposedNode::addSubjectControlLink(), YACS::HMI::SubjectComposedNode::addSubjectLink(), DEBTRACE, YACS::ENGINE::ComposedNode::edAddDFLink(), YACS::ENGINE::ComposedNode::edAddLink(), testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::Node::getInGate(), YACS::ENGINE::Node::getInputDataStreamPort(), YACS::ENGINE::Node::getInputPort(), YACS::HMI::SubjectNode::getName(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getOutGate(), YACS::ENGINE::Node::getOutputDataStreamPort(), YACS::ENGINE::Node::getOutputPort(), YACS::HMI::GuiContext::getProc(), YACS::HMI::INPUTPORT, YACS::ENGINE::OutGate::isAlreadyInSet(), YACS::HMI::OUTPUTPORT, setErrorMsg(), and YASSERT.

◆ localReverse()

bool CommandAddLink::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2972 of file commandsProc.cxx.

2973 {
2974  DEBTRACE("CommandAddLink::localReverse");
2975  try
2976  {
2977  SubjectLink *slink =0;
2978  SubjectControlLink *sclink = 0;
2979  Proc* proc = GuiContext::getCurrent()->getProc();
2980  Node* outn = proc->getChildByName(_outNode);
2981  Node* inn = proc->getChildByName(_inNode);
2982  OutPort* outp;
2983  InPort* inp;
2984  if(_outPortType == OUTPUTPORT)
2985  outp = outn->getOutputPort(_outPort);
2986  else
2987  outp = outn->getOutputDataStreamPort(_outPort);
2988  if(_inPortType == INPUTPORT)
2989  inp = inn->getInputPort(_inPort);
2990  else
2991  inp = inn->getInputDataStreamPort(_inPort);
2992  YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(pair<OutPort*,InPort*>(outp,inp)));
2993  slink = GuiContext::getCurrent()->_mapOfSubjectLink[pair<OutPort*,InPort*>(outp,inp)];
2995  {
2996  YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
2997  sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
2998  }
2999 
3000  Subject *father = slink->getParent();
3001  Subject::erase(slink);
3002  slink = 0;
3003  if (father)
3004  {
3005  DEBTRACE("REMOVE");
3006  father->select(true);
3007  father->update(REMOVE,0,0);
3008  }
3009  if (!sclink)
3010  return true;
3011  father=sclink->getParent();
3012  Subject::erase(sclink);
3013  sclink = 0;
3014  if (father)
3015  {
3016  DEBTRACE("REMOVE");
3017  father->select(true);
3018  father->update(REMOVE,0,0);
3019  }
3020  return true;
3021  }
3022  catch (Exception& ex)
3023  {
3024  DEBTRACE("CommandAddLink::localReverse(): " << ex.what());
3025  setErrorMsg(ex);
3026  return false;
3027  }
3028 }
std::map< std::pair< YACS::ENGINE::OutPort *, YACS::ENGINE::InPort * >, YACS::HMI::SubjectLink * > _mapOfSubjectLink
Definition: guiContext.hxx:72
std::map< std::pair< YACS::ENGINE::Node *, YACS::ENGINE::Node * >, YACS::HMI::SubjectControlLink * > _mapOfSubjectControlLink
Definition: guiContext.hxx:73
virtual void update(GuiEvent event, int type, Subject *son)
static void erase(Subject *sub, Command *command=0, bool post=false)
virtual Subject * getParent()
virtual void select(bool isSelected)

References _controlCreatedWithDF, _inNode, _inPort, _inPortType, YACS::HMI::GuiContext::_mapOfSubjectControlLink, YACS::HMI::GuiContext::_mapOfSubjectLink, _outNode, _outPort, _outPortType, DEBTRACE, YACS::HMI::Subject::erase(), testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getInputDataStreamPort(), YACS::ENGINE::Node::getInputPort(), YACS::ENGINE::Node::getOutputDataStreamPort(), YACS::ENGINE::Node::getOutputPort(), YACS::HMI::Subject::getParent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::INPUTPORT, YACS::HMI::OUTPUTPORT, YACS::HMI::REMOVE, YACS::HMI::Subject::select(), setErrorMsg(), YACS::HMI::Subject::update(), and YASSERT.

Member Data Documentation

◆ _control

bool YACS::HMI::CommandAddLink::_control
protected

Definition at line 514 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

◆ _controlCreatedWithDF

bool YACS::HMI::CommandAddLink::_controlCreatedWithDF
protected

Definition at line 515 of file commandsProc.hxx.

Referenced by CommandAddLink(), localExecute(), and localReverse().

◆ _inNode

std::string YACS::HMI::CommandAddLink::_inNode
protected

Definition at line 511 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

◆ _inPort

std::string YACS::HMI::CommandAddLink::_inPort
protected

Definition at line 512 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

◆ _inPortType

TypeOfElem YACS::HMI::CommandAddLink::_inPortType
protected

Definition at line 513 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

◆ _outNode

std::string YACS::HMI::CommandAddLink::_outNode
protected

Definition at line 508 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

◆ _outPort

std::string YACS::HMI::CommandAddLink::_outPort
protected

Definition at line 509 of file commandsProc.hxx.

Referenced by dump(), localExecute(), and localReverse().

◆ _outPortType

TypeOfElem YACS::HMI::CommandAddLink::_outPortType
protected

Definition at line 510 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().


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