Version: 9.16.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...
 
virtual std::string dump ()
 
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 ()
 
virtual bool localExecute ()=0
 
virtual bool localReverse ()=0
 

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::CommandReparentNode ( std::string  position,
std::string  newParent 
)

Definition at line 364 of file commandsProc.cxx.

366 : Command(), _position(position), _newParent(newParent)
367{
368 DEBTRACE("CommandReparentNode::CommandReparentNode " << _position << " " << _newParent);
369 _oldParent = "";
370}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _newParent, _oldParent, _position, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandReparentNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 372 of file commandsProc.cxx.

373{
374 string ret ="CommandReparentNode " + _position + " " + _newParent;
375 return ret;
376}

References _newParent, and _position.

◆ localExecute()

bool CommandReparentNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 378 of file commandsProc.cxx.

379{
380 DEBTRACE("CommandReparentNode::localExecute");
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");
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());
446 node = 0;
447 }
448 catch (...)
449 {
450 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
451 node = 0;
452 }
453 return (node != 0);
454}
Base class for all composed nodes.
std::string getChildName(const Node *node) const
Node * getChildByName(const std::string &name) const
std::string getName() const
virtual void edRemoveChild(Node *node)
Remove a child node.
virtual bool edAddChild(Node *DISOWNnode)
Base class for dynamically (fully or semifully) built graphs.
Definition: DynParaLoop.hxx:41
Base class for loop node.
Definition: Loop.hxx:147
Base class for all nodes.
Definition: Node.hxx:70
const std::string & getName() const
Definition: Node.hxx:125
ComposedNode * getFather() const
Definition: Node.hxx:127
Base class for all schema objects.
Definition: Proc.hxx:44
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
std::string _lastErrorMessage
Definition: guiContext.hxx:79
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:70
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
static TypeOfElem getTypeOfNode(YACS::ENGINE::Node *node)
virtual void houseKeepingAfterCutPaste(bool isCut, SubjectNode *son)
virtual void removeExternalControlLinks()
virtual void update(GuiEvent event, int type, Subject *son)
virtual void restoreLinks()
virtual void recursiveUpdate(GuiEvent event, int type, Subject *son)
virtual void removeExternalLinks()
virtual void saveLinks()
void setErrorMsg(YACS::Exception &ex)

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(), testCppPluginInvokation::ex, 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(), and YACS::HMI::SubjectNode::update().

◆ localReverse()

bool CommandReparentNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 456 of file commandsProc.cxx.

457{
458 DEBTRACE("CommandReparentNode::localReverse " << _newpos << " " << _oldParent);
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 }
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());
496 node = 0;
497 }
498 catch (...)
499 {
500 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
501 node = 0;
502 }
503 return (node != 0);
504}

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(), testCppPluginInvokation::ex, 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(), and YACS::HMI::SubjectNode::update().

Member Data Documentation

◆ _newParent

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

Definition at line 146 of file commandsProc.hxx.

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

◆ _newpos

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

Definition at line 148 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

◆ _oldParent

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

Definition at line 147 of file commandsProc.hxx.

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

◆ _position

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: