Version: 8.3.0
YACS::HMI::CommandCopyNode Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandCopyNode:
Collaboration diagram for YACS::HMI::CommandCopyNode:

Public Member Functions

 CommandCopyNode (YACS::ENGINE::Proc *fromproc, std::string position, std::string newParent, int acase=0)
 
YACS::ENGINE::NodegetNode ()
 
- 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 _position
 
std::string _newParent
 
std::string _newName
 
int _case
 
YACS::ENGINE::Node_clone
 
YACS::ENGINE::Proc_fromproc
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 169 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandCopyNode::CommandCopyNode ( YACS::ENGINE::Proc fromproc,
std::string  position,
std::string  newParent,
int  acase = 0 
)

Definition at line 668 of file commandsProc.cxx.

References _newParent, _position, and DEBTRACE.

672  : Command(), _fromproc(fromproc), _position(position), _newParent(newParent), _newName(""), _clone(0), _case(swCase)
673 {
674  DEBTRACE("CommandCopyNode::CommandCopyNode " << _position << " " << _newParent);
675 }

Member Function Documentation

std::string CommandCopyNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 677 of file commandsProc.cxx.

References _newParent, _position, and PMMLBasicsTestLauncher::ret.

678 {
679  string ret ="CommandCopyNode " + _position + " " + _newParent;
680  return ret;
681 }
YACS::ENGINE::Node * CommandCopyNode::getNode ( )

Definition at line 683 of file commandsProc.cxx.

References _clone.

684 {
685  return _clone;
686 }
bool CommandCopyNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 688 of file commandsProc.cxx.

References _case, _clone, _fromproc, YACS::HMI::GuiContext::_mapOfSubjectNode, _newName, _newParent, _position, YACS::HMI::SubjectComposedNode::addSubjectNode(), YACS::ENGINE::Node::cloneWithoutCompAndContDeepCpy(), DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::Node::getQualifiedName(), YACS::HMI::Subject::loadChildren(), YACS::HMI::Subject::loadLinks(), setErrorMsg(), YACS::ENGINE::Node::setName(), and YACS::Exception::what().

689 {
690  DEBTRACE("CommandCopyNode::localExecute");
691  Proc* proc = GuiContext::getCurrent()->getProc();
692  Node* node = 0;
693  try
694  {
695  if (_position == _fromproc->getName())
696  throw YACS::Exception("Copy the proc (main bloc) is impossible");
698  ComposedNode *oldFather = node->getFather();
699  ComposedNode *newFather = proc;
700  Node *newF = 0;
701  if (_newParent != proc->getName())
702  {
703  newF = proc->getChildByName(_newParent);
704  newFather = dynamic_cast<ComposedNode*>(newF);
705  }
706  if (!newFather)
707  throw YACS::Exception("new parent must be a composed node");
708  if (Loop *loop = dynamic_cast<Loop*>(newFather))
709  if (!loop->edGetDirectDescendants().empty())
710  throw YACS::Exception("Already a node in a new parent of Loop type");
711  //_clone = node->cloneWithoutCompAndContDeepCpy(newFather);
713  if (!_clone)
714  throw YACS::Exception("Node cannot be cloned");
715  int nodeSuffix = -1;
716  bool sameName = true;
717  stringstream s;
718  do
719  {
720  s.str("");
721  s << node->getName();
722  if (nodeSuffix >= 0) // --- first try <0 means without suffix
723  s << nodeSuffix;
724  DEBTRACE(s.str());
725  try
726  {
727  Node *nodeSameName = newFather->getChildByName(s.str());
728  }
729  catch (Exception& e)
730  {
731  sameName = false;
732  }
733  nodeSuffix++;
734  }
735  while(sameName);
736  _clone->setName(s.str());
737  _newName = _clone->getName();
738 
739  if (YACS::ENGINE::Switch* theswitch = dynamic_cast<YACS::ENGINE::Switch*>(newFather))
740  {
741  DEBTRACE("father is a switch " << newFather->getName());
742  int theCase=_case;
743  if(theswitch->edGetNode(_case))
744  {
745  //the case is already used. Try another one
746  theCase=theswitch->getMaxCase()+1;
747  }
748  theswitch->edSetNode(theCase,_clone);
749  }
750  else
751  newFather->edAddChild(_clone);
752 
755 
757  SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(sub);
758  SubjectNode *son = snp->addSubjectNode(_clone);
759  son->loadChildren();
760  son->loadLinks();
761  }
762  catch (Exception& ex)
763  {
764  DEBTRACE("CommandCopyNode::localExecute() : " << ex.what());
765  setErrorMsg(ex);
766  _clone = 0;
767  }
768  return (_clone != 0);
769 }
bool CommandCopyNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 771 of file commandsProc.cxx.

References _clone, YACS::HMI::GuiContext::_mapOfSubjectNode, _newName, _newParent, _position, DEBTRACE, YACS::HMI::Subject::erase(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::Subject::getParent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::REMOVE, YACS::HMI::Subject::select(), setErrorMsg(), YACS::HMI::Subject::update(), YACS::Exception::what(), and YASSERT.

772 {
773  DEBTRACE("CommandCopyNode::localReverse " << _position << " " << _newParent);
774  try
775  {
776  Proc* proc = GuiContext::getCurrent()->getProc();
777  string nodeName = _newParent + "." + _newName;
778  if (_newParent == proc->getName())
779  nodeName = _newName;
780  DEBTRACE(nodeName);
781  _clone = proc->getChildByName(nodeName);
782 
783  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_clone));
785  Subject *father = snode->getParent();
786  Subject::erase(snode);
787  _clone = 0;
788  if (father)
789  {
790  DEBTRACE("REMOVE");
791  father->select(true);
792  father->update(REMOVE,0,0);
793  }
794  return true;
795  }
796  catch (Exception& ex)
797  {
798  DEBTRACE("CommandCopyNode::localReverse(): " << ex.what());
799  setErrorMsg(ex);
800  return false;
801  }
802  return true;
803 }

Member Data Documentation

int YACS::HMI::CommandCopyNode::_case
protected

Definition at line 184 of file commandsProc.hxx.

Referenced by localExecute().

YACS::ENGINE::Node* YACS::HMI::CommandCopyNode::_clone
protected

Definition at line 185 of file commandsProc.hxx.

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

YACS::ENGINE::Proc* YACS::HMI::CommandCopyNode::_fromproc
protected

Definition at line 186 of file commandsProc.hxx.

Referenced by localExecute().

std::string YACS::HMI::CommandCopyNode::_newName
protected

Definition at line 183 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

std::string YACS::HMI::CommandCopyNode::_newParent
protected

Definition at line 182 of file commandsProc.hxx.

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

std::string YACS::HMI::CommandCopyNode::_position
protected

Definition at line 181 of file commandsProc.hxx.

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


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