Version: 8.3.0
YACS::HMI::CommandPutInComposedNode Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandPutInComposedNode:
Collaboration diagram for YACS::HMI::CommandPutInComposedNode:

Public Member Functions

 CommandPutInComposedNode (std::string position, std::string newParent, std::string type, bool toSaveRestoreLinks=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 _position
 
std::string _newParent
 
std::string _type
 
std::string _newpos
 
bool _toSaveRestoreLinks
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 151 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandPutInComposedNode::CommandPutInComposedNode ( std::string  position,
std::string  newParent,
std::string  type,
bool  toSaveRestoreLinks = true 
)

Definition at line 507 of file commandsProc.cxx.

References _newParent, _newpos, _position, and DEBTRACE.

511  : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
512 {
513  DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
514  _newpos ="";
515 }

Member Function Documentation

std::string CommandPutInComposedNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 517 of file commandsProc.cxx.

References _newParent, _position, _toSaveRestoreLinks, _type, and PMMLBasicsTestLauncher::ret.

518 {
519  string save = _toSaveRestoreLinks ? "true" : "false";
520  string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save;
521  return ret;
522 }
bool CommandPutInComposedNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 525 of file commandsProc.cxx.

References YACS::ENGINE::Catalog::_composednodeMap, YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectNode, _newParent, _newpos, _position, _toSaveRestoreLinks, _type, YACS::HMI::SubjectComposedNode::addSubjectNode(), YACS::ENGINE::Node::cloneWithoutCompAndContDeepCpy(), YACS::HMI::CUT, DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::edRemoveChild(), YACS::ENGINE::Runtime::getBuiltinCatalog(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComposedNode::getChildName(), YACS::ENGINE::Bloc::getChildren(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::getSALOMERuntime(), 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(), YACS::HMI::Subject::select(), setErrorMsg(), YACS::ENGINE::Node::setName(), YACS::HMI::Subject::setParent(), YACS::HMI::SubjectNode::update(), and YACS::Exception::what().

526 {
527  DEBTRACE("CommandPutInComposedNode::localExecute");
528  Proc* proc = GuiContext::getCurrent()->getProc();
529  Node* node = 0;
530  try
531  {
532  if (_position == proc->getName())
533  throw YACS::Exception("You cannot put the proc (main bloc) in a " + _type);
534  node = proc->getChildByName(_position);
535  ComposedNode *oldFather = node->getFather();
537  Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
538  SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
540  snode->saveLinks(); //save existing links
541  //remove external links
542  snode->removeExternalLinks();
544  //remove subject node from subject old father
545  sop->houseKeepingAfterCutPaste(true, snode);
546  //remove node from old father
547  oldFather->edRemoveChild(node);
548  //refresh node views
549  sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
550 
551  // try to find a node with the given name:
552  // success: use it as target composed node
553  // fail: create such a node and use it
554  std::list<Node*> children = proc->getChildren();
555  Node* composednode = 0;
556  SubjectNode *scomposednode = 0;
557  for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
558  {
559  if ( _newParent == (*it)->getName() )
560  {
561  //get an existing ComposedNode with name _newParent
562  composednode = (*it);
563  break;
564  }
565  }
566  // target node was found
567  if ( composednode )
568  {
569  scomposednode = GuiContext::getCurrent()->_mapOfSubjectNode[composednode];
570  }
571  // creation of target node
572  else
573  {
574  //create a ComposedNode (type _type) with name _newParent
576  Node* nodeToClone = catalog->_composednodeMap[_type];
577  composednode = nodeToClone->cloneWithoutCompAndContDeepCpy(0);
578  composednode->setName(_newParent);
579  //add the new composednode as child of oldfather
580  oldFather->edAddChild(composednode);
581  //create the subject composednode
582  scomposednode = sop->addSubjectNode(composednode,"",catalog,"",_type);
583  }
584 
585  //add the old node as child of new composednode
586  (dynamic_cast<YACS::ENGINE::ComposedNode*>(composednode))->edAddChild(node);
587  _newpos = proc->getChildName(node);
588  //add the subject node to subject composednode
589  (dynamic_cast<SubjectComposedNode*>(scomposednode))->houseKeepingAfterCutPaste(false, snode);
590  snode->setParent(scomposednode);
592  snode->restoreLinks(); //restore links
593  //refresh all views
594  scomposednode->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
595  snode->recursiveUpdate(RENAME, 0, snode);
596  snode->select(true);
597  }
598  catch (Exception& ex)
599  {
600  DEBTRACE("CommandPutInComposedNode::localExecute() : " << ex.what());
601  setErrorMsg(ex);
602  node = 0;
603  }
604  catch (...)
605  {
606  GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
607  node = 0;
608  }
609  return (node != 0);
610 }
bool CommandPutInComposedNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 612 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_mapOfSubjectNode, _newpos, YACS::HMI::CUT, DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::edRemoveChild(), YACS::HMI::Subject::erase(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComposedNode::getChildName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Node::getFather(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::GuiContext::getSubjectProc(), 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(), YACS::HMI::Subject::select(), setErrorMsg(), YACS::HMI::Subject::setParent(), YACS::HMI::SubjectNode::update(), YACS::Exception::what(), and YASSERT.

613 {
614  DEBTRACE("CommandPutInComposedNode::localReverse");
615  Proc* proc = GuiContext::getCurrent()->getProc();
616  Node* node = 0;
617  try
618  {
619  YASSERT(_newpos != proc->getName())
620  node = proc->getChildByName(_newpos);
621  ComposedNode *oldFather = node->getFather();
623  Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
624  SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
625  //save existing links
626  snode->saveLinks();
627  //remove external links
628  snode->removeExternalLinks();
630  //remove subject node from subject old father
631  sop->houseKeepingAfterCutPaste(true, snode);
632  //remove node from old father
633  oldFather->edRemoveChild(node);
634  //refresh node views, temporary paste in proc to keep widgets associated to node
635  sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
637 
638  //remove composed node oldFather
639  ComposedNode *oldGrandFather = oldFather->getFather();
640  Subject *subog = GuiContext::getCurrent()->_mapOfSubjectNode[oldGrandFather];
641  SubjectComposedNode* sogp = dynamic_cast<SubjectComposedNode*>(subog);
642  Subject::erase(sop);
643 
644  //add the old node as child of new composednode
645  oldGrandFather->edAddChild(node);
646  _newpos = proc->getChildName(node);
647  //add the subject node to subject composednode
648  sogp->houseKeepingAfterCutPaste(false, snode);
649  snode->setParent(sogp);
650  //restore links
651  snode->restoreLinks();
652  //refresh all views
654  sogp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
655  snode->recursiveUpdate(RENAME, 0, snode);
656  snode->select(true);
657  }
658  catch (Exception& ex)
659  {
660  DEBTRACE("CommandPutInComposedNode::localReverse() : " << ex.what());
661  setErrorMsg(ex);
662  node = 0;
663  }
664  return (node != 0);
665 }

Member Data Documentation

std::string YACS::HMI::CommandPutInComposedNode::_newParent
protected

Definition at line 163 of file commandsProc.hxx.

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

std::string YACS::HMI::CommandPutInComposedNode::_newpos
protected

Definition at line 165 of file commandsProc.hxx.

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

std::string YACS::HMI::CommandPutInComposedNode::_position
protected

Definition at line 162 of file commandsProc.hxx.

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

bool YACS::HMI::CommandPutInComposedNode::_toSaveRestoreLinks
protected

Definition at line 166 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

std::string YACS::HMI::CommandPutInComposedNode::_type
protected

Definition at line 164 of file commandsProc.hxx.

Referenced by dump(), and localExecute().


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