Version: 9.16.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...
 
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 _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::CommandCopyNode ( YACS::ENGINE::Proc fromproc,
std::string  position,
std::string  newParent,
int  acase = 0 
)

Definition at line 668 of file commandsProc.cxx.

672 : Command(), _fromproc(fromproc), _position(position), _newParent(newParent), _newName(""), _clone(0), _case(swCase)
673{
674 DEBTRACE("CommandCopyNode::CommandCopyNode " << _position << " " << _newParent);
675}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
YACS::ENGINE::Node * _clone
YACS::ENGINE::Proc * _fromproc

References _newParent, _position, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandCopyNode::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 677 of file commandsProc.cxx.

678{
679 string ret ="CommandCopyNode " + _position + " " + _newParent;
680 return ret;
681}

References _newParent, and _position.

◆ getNode()

YACS::ENGINE::Node * CommandCopyNode::getNode ( )

Definition at line 683 of file commandsProc.cxx.

684{
685 return _clone;
686}

References _clone.

◆ localExecute()

bool CommandCopyNode::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 688 of file commandsProc.cxx.

689{
690 DEBTRACE("CommandCopyNode::localExecute");
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());
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());
766 _clone = 0;
767 }
768 return (_clone != 0);
769}
Base class for all composed nodes.
Node * getChildByName(const std::string &name) const
std::string getName() const
virtual bool edAddChild(Node *DISOWNnode)
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
std::string getQualifiedName() const
same as Node::getName() in most cases, but differs for children of switch
Definition: Node.cxx:632
void setName(const std::string &name)
Change the name of the node.
Definition: Node.cxx:162
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
Control node that emulates the C switch.
Definition: Switch.hxx:85
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:70
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
SubjectNode * addSubjectNode(YACS::ENGINE::Node *node, std::string name="", YACS::ENGINE::Catalog *catalog=0, std::string compo="", std::string type="")
virtual void loadLinks()
virtual void loadChildren()
void setErrorMsg(YACS::Exception &ex)

References _case, _clone, _fromproc, YACS::HMI::GuiContext::_mapOfSubjectNode, _newName, _newParent, _position, YACS::HMI::SubjectComposedNode::addSubjectNode(), YACS::ENGINE::Node::cloneWithoutCompAndContDeepCpy(), DEBTRACE, YACS::ENGINE::ComposedNode::edAddChild(), testCppPluginInvokation::ex, 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(), and YACS::ENGINE::Node::setName().

◆ localReverse()

bool CommandCopyNode::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 771 of file commandsProc.cxx.

772{
773 DEBTRACE("CommandCopyNode::localReverse " << _position << " " << _newParent);
774 try
775 {
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());
800 return false;
801 }
802 return true;
803}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
virtual void update(GuiEvent event, int type, Subject *son)
static void erase(Subject *sub, Command *command=0, bool post=false)
virtual Subject * getParent()
virtual void select(bool isSelected)

References _clone, YACS::HMI::GuiContext::_mapOfSubjectNode, _newName, _newParent, _position, DEBTRACE, YACS::HMI::Subject::erase(), testCppPluginInvokation::ex, 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(), and YASSERT.

Member Data Documentation

◆ _case

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

Definition at line 184 of file commandsProc.hxx.

Referenced by localExecute().

◆ _clone

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

Definition at line 185 of file commandsProc.hxx.

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

◆ _fromproc

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

Definition at line 186 of file commandsProc.hxx.

Referenced by localExecute().

◆ _newName

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

Definition at line 183 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

◆ _newParent

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

Definition at line 182 of file commandsProc.hxx.

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

◆ _position

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: