Version: 8.3.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 ( std::string  outNode,
std::string  outPort,
TypeOfElem  outPortType,
std::string  inNode,
std::string  inPort,
TypeOfElem  inPortType,
bool  control = true 
)

Definition at line 2855 of file commandsProc.cxx.

References _controlCreatedWithDF, and DEBTRACE.

2857  : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2858  _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2859 {
2860  DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2861  _controlCreatedWithDF = false;
2862 }

Member Function Documentation

std::string CommandAddLink::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2864 of file commandsProc.cxx.

References _control, _inNode, _inPort, _outNode, _outPort, and PMMLBasicsTestLauncher::ret.

2865 {
2866  string s = "false";
2867  if (_control) s = "true";
2868  string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2869  return ret;
2870 }
bool CommandAddLink::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2872 of file commandsProc.cxx.

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(), 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::ENGINE::ComposedNode::getName(), YACS::HMI::SubjectNode::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(), YACS::Exception::what(), and YASSERT.

2873 {
2874  DEBTRACE("CommandAddLink::localExecute");
2875  DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2876  try
2877  {
2878  Proc* proc = GuiContext::getCurrent()->getProc();
2879  Node* outn = proc->getChildByName(_outNode);
2880  Node* inn = proc->getChildByName(_inNode);
2881  OutPort* outp;
2882  InPort* inp;
2883 
2884  // --- is a control link already existing ?
2885  bool preexistingControl = false;
2886  {
2887  Node* outn2=outn;
2888  Node* inn2=inn;
2889  ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2890  if(outn2==father || inn2==father)
2891  preexistingControl = true;
2892  else
2893  {
2894  while(outn2->getFather() != father)
2895  outn2 = outn2->getFather();
2896  while(inn2->getFather() != father)
2897  inn2 = inn2->getFather();
2898  OutGate *ogate = outn2->getOutGate();
2899  InGate *igate = inn2->getInGate();
2900  if (ogate->isAlreadyInSet(igate))
2901  preexistingControl = true;
2902  }
2903  }
2904 
2905  if(_outPortType == OUTPUTPORT)
2906  outp = outn->getOutputPort(_outPort);
2907  else
2908  outp = outn->getOutputDataStreamPort(_outPort);
2909 
2910  if(_inPortType == INPUTPORT)
2911  inp = inn->getInputPort(_inPort);
2912  else
2913  inp = inn->getInputDataStreamPort(_inPort);
2914 
2915  ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2916  DEBTRACE(cla->getName());
2917  if (dynamic_cast<OutputDataStreamPort*>(outp))
2918  cla->edAddLink(outp,inp);
2919  else if(_control)
2920  cla->edAddDFLink(outp,inp);
2921  else
2922  cla->edAddLink(outp,inp);
2923 
2924  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2926  SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2927  DEBTRACE(scla->getName());
2932  SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2933 
2934  // --- if control link, identify the nodes linked and draw the control link if not already existing
2935 
2936  if (_control)
2937  {
2938  ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2939  if(outn==father || inn==father) return true;
2940  while(outn->getFather() != father)
2941  outn = outn->getFather();
2942  while(inn->getFather() != father)
2943  inn = inn->getFather();
2944  OutGate *ogate = outn->getOutGate();
2945  InGate *igate = inn->getInGate();
2946  if (ogate->isAlreadyInSet(igate))
2947  {
2948  if (!preexistingControl)
2949  _controlCreatedWithDF = true;
2950  pair<Node*,Node*> keyLink(outn,inn);
2951  if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2952  {
2955  if (!sfno || !sfni) return true;
2956  SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2957  }
2958  }
2959  }
2960  return true;
2961  }
2962  catch (Exception& ex)
2963  {
2964  DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2965  setErrorMsg(ex);
2966  return false;
2967  }
2968 }
bool CommandAddLink::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2970 of file commandsProc.cxx.

References _controlCreatedWithDF, _inNode, _inPort, _inPortType, YACS::HMI::GuiContext::_mapOfSubjectControlLink, YACS::HMI::GuiContext::_mapOfSubjectLink, _outNode, _outPort, _outPortType, DEBTRACE, YACS::HMI::Subject::erase(), 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(), YACS::Exception::what(), and YASSERT.

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

Member Data Documentation

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

Definition at line 514 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

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

Definition at line 515 of file commandsProc.hxx.

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

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

Definition at line 511 of file commandsProc.hxx.

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

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

Definition at line 512 of file commandsProc.hxx.

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

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

Definition at line 513 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

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

Definition at line 508 of file commandsProc.hxx.

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

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

Definition at line 509 of file commandsProc.hxx.

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

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: