Version: 8.3.0
YACS::HMI::CommandReparentNode Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandReparentNode:
Collaboration diagram for YACS::HMI::CommandReparentNode:

Public Member Functions

 CommandReparentNode (std::string position, std::string newParent)
 
- 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 _oldParent
 
std::string _newpos
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 136 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandReparentNode::CommandReparentNode ( std::string  position,
std::string  newParent 
)

Definition at line 364 of file commandsProc.cxx.

References _newParent, _oldParent, _position, and DEBTRACE.

366  : Command(), _position(position), _newParent(newParent)
367 {
368  DEBTRACE("CommandReparentNode::CommandReparentNode " << _position << " " << _newParent);
369  _oldParent = "";
370 }

Member Function Documentation

std::string CommandReparentNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 372 of file commandsProc.cxx.

References _newParent, _position, and PMMLBasicsTestLauncher::ret.

373 {
374  string ret ="CommandReparentNode " + _position + " " + _newParent;
375  return ret;
376 }
bool CommandReparentNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 378 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectNode, _newParent, _newpos, _oldParent, YACS::HMI::Subject::_parent, _position, YACS::HMI::CUT, DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::edRemoveChild(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComposedNode::getChildName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Node::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::ProcInvoc::getTypeOfNode(), YACS::HMI::SubjectComposedNode::houseKeepingAfterCutPaste(), YACS::HMI::PASTE, YACS::HMI::SubjectNode::recursiveUpdate(), YACS::HMI::SubjectNode::removeExternalControlLinks(), YACS::HMI::SubjectNode::removeExternalLinks(), YACS::HMI::RENAME, YACS::HMI::SubjectNode::restoreLinks(), YACS::HMI::SubjectNode::saveLinks(), setErrorMsg(), YACS::HMI::SubjectNode::update(), and YACS::Exception::what().

379 {
380  DEBTRACE("CommandReparentNode::localExecute");
381  Proc* proc = GuiContext::getCurrent()->getProc();
382  Node* node = 0;
383  try
384  {
385  if (_position == proc->getName())
386  throw YACS::Exception("Reparent the proc (main bloc) is impossible");
387  node = proc->getChildByName(_position);
388  ComposedNode *oldFather = node->getFather();
389  ComposedNode *newFather = proc;
390  Node *newF = 0;
391  if (_newParent != proc->getName())
392  {
393  newF = proc->getChildByName(_newParent);
394  newFather = dynamic_cast<ComposedNode*>(newF);
395  }
396  if (!newFather)
397  throw YACS::Exception("new parent must be a composed node");
398  if (oldFather == newFather)
399  throw YACS::Exception("no need to reparent to the same parent");
400  if (ComposedNode *cnode = dynamic_cast<ComposedNode*>(node))
401  if (cnode->isInMyDescendance(newFather))
402  throw YACS::Exception("reparent a node to one of it's children is impossible");
403  if (Loop *loop = dynamic_cast<Loop*>(newFather))
404  if (!loop->edGetDirectDescendants().empty())
405  throw YACS::Exception("Already a node in a new parent of Loop type");
406  if (DynParaLoop * dpl = dynamic_cast<DynParaLoop*>(newFather))
407  if (dpl->getExecNode() != NULL)
408  throw YACS::Exception("Already an execution node in the new parent of type dynamic loop");
409  Node *nodeSameName = 0;
410  try
411  {
412  nodeSameName = newFather->getChildByName(node->getName());
413  }
414  catch (Exception& e)
415  {
416  }
417  if (nodeSameName)
418  throw YACS::Exception("there is already a child of same name in the new parent");
420  Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
421  Subject *subn = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
422  SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
423  SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
424  //save existing links
425  snode->saveLinks();
426  snode->removeExternalLinks();
428  sop->houseKeepingAfterCutPaste(true, snode);
429  oldFather->edRemoveChild(node);
430  newFather->edAddChild(node);
431  snp->houseKeepingAfterCutPaste(false, snode);
432  //restore links
433  snode->restoreLinks();
434  if (oldFather == proc) _oldParent = proc->getName();
435  else _oldParent = proc->getChildName(oldFather);
436  _newpos = proc->getChildName(node);
437  sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
438  snp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
439  snode->recursiveUpdate(RENAME, 0, snode);
440  snode->_parent = snp;
441  }
442  catch (Exception& ex)
443  {
444  DEBTRACE("CommandReparentNode::localExecute() : " << ex.what());
445  setErrorMsg(ex);
446  node = 0;
447  }
448  catch (...)
449  {
450  GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
451  node = 0;
452  }
453  return (node != 0);
454 }
bool CommandReparentNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 456 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectNode, _newpos, _oldParent, YACS::HMI::Subject::_parent, YACS::HMI::CUT, DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::edRemoveChild(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::ProcInvoc::getTypeOfNode(), YACS::HMI::SubjectComposedNode::houseKeepingAfterCutPaste(), YACS::HMI::PASTE, YACS::HMI::SubjectNode::recursiveUpdate(), YACS::HMI::SubjectNode::removeExternalControlLinks(), YACS::HMI::SubjectNode::removeExternalLinks(), YACS::HMI::RENAME, YACS::HMI::SubjectNode::restoreLinks(), YACS::HMI::SubjectNode::saveLinks(), setErrorMsg(), YACS::HMI::SubjectNode::update(), and YACS::Exception::what().

457 {
458  DEBTRACE("CommandReparentNode::localReverse " << _newpos << " " << _oldParent);
459  Proc* proc = GuiContext::getCurrent()->getProc();
460  Node* node = 0;
461  try
462  {
463  node = proc->getChildByName(_newpos);
464  ComposedNode *father = node->getFather();
465  ComposedNode *oldFather = proc;
466  Node *oldF = 0;
467  if (_oldParent != proc->getName())
468  {
469  oldF = proc->getChildByName(_oldParent);
470  oldFather = dynamic_cast<ComposedNode*>(oldF);
471  }
474  Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
475  SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
476  SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
477  //save existing links
478  snode->saveLinks();
479  snode->removeExternalLinks();
481  snp->houseKeepingAfterCutPaste(true, snode);
482  father->edRemoveChild(node);
483  oldFather->edAddChild(node);
484  sop->houseKeepingAfterCutPaste(false, snode);
485  //restore links
486  snode->restoreLinks();
487  snp->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
488  sop->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
489  snode->recursiveUpdate(RENAME, 0, snode);
490  snode->_parent = sop;
491  }
492  catch (Exception& ex)
493  {
494  DEBTRACE("CommandReparentNode::localReverse() : " << ex.what());
495  setErrorMsg(ex);
496  node = 0;
497  }
498  catch (...)
499  {
500  GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
501  node = 0;
502  }
503  return (node != 0);
504 }

Member Data Documentation

std::string YACS::HMI::CommandReparentNode::_newParent
protected

Definition at line 146 of file commandsProc.hxx.

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

std::string YACS::HMI::CommandReparentNode::_newpos
protected

Definition at line 148 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

std::string YACS::HMI::CommandReparentNode::_oldParent
protected

Definition at line 147 of file commandsProc.hxx.

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

std::string YACS::HMI::CommandReparentNode::_position
protected

Definition at line 145 of file commandsProc.hxx.

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


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