Version: 9.15.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::CommandPutInComposedNode ( std::string  position,
std::string  newParent,
std::string  type,
bool  toSaveRestoreLinks = true 
)

Definition at line 507 of file commandsProc.cxx.

511  : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
512 {
513  DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
514  _newpos ="";
515 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _newParent, _newpos, _position, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandPutInComposedNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 517 of file commandsProc.cxx.

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

References _newParent, _position, _toSaveRestoreLinks, and _type.

◆ localExecute()

bool CommandPutInComposedNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 525 of file commandsProc.cxx.

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 }
std::list< Node * > getChildren() const
Definition: Bloc.hxx:57
class for YACS catalogs.
Definition: Catalog.hxx:42
std::map< std::string, ComposedNode * > _composednodeMap
Definition: Catalog.hxx:52
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 all nodes.
Definition: Node.hxx:70
void setName(const std::string &name)
Change the name of the node.
Definition: Node.cxx:162
ComposedNode * getFather() const
Definition: Node.hxx:127
Node * cloneWithoutCompAndContDeepCpy(ComposedNode *father, bool editionOnly=true) const
This method MUST NEVER BE VIRTUAL
Definition: Node.cxx:150
Base class for all schema objects.
Definition: Proc.hxx:44
Catalog * getBuiltinCatalog()
Get the catalog of base nodes (elementary and composed)
Definition: Runtime.cxx:314
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
std::string _lastErrorMessage
Definition: guiContext.hxx:79
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:68
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
static TypeOfElem getTypeOfNode(YACS::ENGINE::Node *node)
SubjectNode * addSubjectNode(YACS::ENGINE::Node *node, std::string name="", YACS::ENGINE::Catalog *catalog=0, std::string compo="", std::string type="")
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()
virtual void setParent(Subject *son)
virtual void select(bool isSelected)
void setErrorMsg(YACS::Exception &ex)
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()

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

◆ localReverse()

bool CommandPutInComposedNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 612 of file commandsProc.cxx.

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();
622  SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
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();
629  snode->removeExternalControlLinks();
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);
636  GuiContext::getCurrent()->getSubjectProc()->update(PASTE, 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
653  GuiContext::getCurrent()->getSubjectProc()->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
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 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59

References YACS::HMI::GuiContext::_mapOfSubjectNode, _newpos, YACS::HMI::CUT, DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), YACS::ENGINE::ComposedNode::edRemoveChild(), YACS::HMI::Subject::erase(), testCppPluginInvokation::ex, 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(), and YASSERT.

Member Data Documentation

◆ _newParent

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

Definition at line 163 of file commandsProc.hxx.

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

◆ _newpos

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

Definition at line 165 of file commandsProc.hxx.

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

◆ _position

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

Definition at line 162 of file commandsProc.hxx.

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

◆ _toSaveRestoreLinks

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

Definition at line 166 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

◆ _type

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: