Version: 9.16.0
YACS::HMI::Command Class Referenceabstract

#include <commands.hxx>

Inheritance diagram for YACS::HMI::Command:
Collaboration diagram for YACS::HMI::Command:

Public Member Functions

 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 ()=0
 
virtual bool localReverse ()=0
 

Protected Attributes

std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 38 of file commands.hxx.

Constructor & Destructor Documentation

◆ Command()

Command::Command ( )

Definition at line 37 of file commands.cxx.

38{
39 _subCommands.clear();
40 _normalReverse = true;
41}
std::vector< Command * > _subCommands
Definition: commands.hxx:52

References _normalReverse, and _subCommands.

Member Function Documentation

◆ addSubCommand()

void Command::addSubCommand ( Command command)

Definition at line 134 of file commands.cxx.

135{
136 _subCommands.push_back(command);
137}

References _subCommands.

◆ dump()

std::string Command::dump ( )
virtual

Reimplemented in YACS::HMI::CommandAddNodeFromCatalog, YACS::HMI::CommandReparentNode, YACS::HMI::CommandPutInComposedNode, YACS::HMI::CommandCopyNode, YACS::HMI::CommandRenameNode, YACS::HMI::CommandRenameContainer, YACS::HMI::CommandRenameInDataPort, YACS::HMI::CommandRenameOutDataPort, YACS::HMI::CommandAddDataTypeFromCatalog, YACS::HMI::CommandAddInputPortFromCatalog, YACS::HMI::CommandAddOutputPortFromCatalog, YACS::HMI::CommandAddIDSPortFromCatalog, YACS::HMI::CommandAddODSPortFromCatalog, YACS::HMI::CommandOrderInputPorts, YACS::HMI::CommandOrderOutputPorts, YACS::HMI::CommandSetInPortValue, YACS::HMI::CommandSetOutPortValue, YACS::HMI::CommandSetSwitchSelect, YACS::HMI::CommandSetSwitchCase, YACS::HMI::CommandSetForLoopSteps, YACS::HMI::CommandSetWhileCondition, YACS::HMI::CommandSetForEachBranch, YACS::HMI::CommandSetAlgo, YACS::HMI::CommandAddLink, YACS::HMI::CommandAddControlLink, YACS::HMI::CommandAddContainer, YACS::HMI::CommandAddHPContainer, YACS::HMI::CommandSetContainerProperties, YACS::HMI::CommandSetNodeProperties, YACS::HMI::CommandSetComponentInstanceProperties, YACS::HMI::CommandSetDSPortProperties, YACS::HMI::CommandSetLinkProperties, YACS::HMI::CommandSetFuncNodeFunctionName, YACS::HMI::CommandSetInlineNodeScript, YACS::HMI::CommandAddComponentInstance, YACS::HMI::CommandSetExecutionMode, YACS::HMI::CommandSetContainer, YACS::HMI::CommandAssociateComponentToContainer, YACS::HMI::CommandAssociateServiceToComponent, YACS::HMI::CommandAddComponentFromCatalog, and YACS::HMI::CommandDestroy.

Definition at line 119 of file commands.cxx.

120{
121 return "=== generic command dump ===";
122}

Referenced by recursiveDump().

◆ execute()

bool Command::execute ( )
virtual

the command is executed a first time after its registration for undo redo, then on redo

Execute may induce subcommands to be registered during its execution. Subcommands must be deleted before redo, to be recreated by redo. CommandDestroy is a special case, where subcommands are registered before Execute, and undo action calls executeSubOnly instead of reverse. Subcommands pf CommandDestroy must not be deleted.

Definition at line 51 of file commands.cxx.

52{
53 if ( !GuiContext::getCurrent() || !GuiContext::getCurrent()->getInvoc() )
54 return false;
55
56 bool commandInProgress = !GuiContext::getCurrent()->getInvoc()->isSpecialReverse();
57 if (commandInProgress)
59
60 bool ret=true;
61 if (GuiContext::getCurrent()->getInvoc()->_isRedo && _normalReverse)
62 {
63 for (int i=0; i<_subCommands.size(); i++)
64 delete _subCommands[i];
65 _subCommands.clear();
66 }
67 ret = localExecute();
68 if (ret) GuiContext::getCurrent()->setNotSaved(true);
69
70 if (commandInProgress)
72 return ret;
73}
virtual bool localExecute()=0
void setNotSaved(bool isNotSaved)
Definition: guiContext.hxx:64
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
YACS::HMI::ProcInvoc * getInvoc()
Definition: guiContext.hxx:51
std::vector< Command * > _commandsInProgress
Definition: commands.hxx:74

References YACS::HMI::Invocator::_commandsInProgress, _normalReverse, _subCommands, YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getInvoc(), yacsorb.CORBAEngineTest::i, YACS::HMI::Invocator::isSpecialReverse(), localExecute(), and YACS::HMI::GuiContext::setNotSaved().

Referenced by YACS::HMI::SubjectProc::addComponent(), YACS::HMI::SubjectProc::addComSubjectDataType(), YACS::HMI::SubjectProc::addContainer(), YACS::HMI::SubjectProc::addDataType(), YACS::HMI::SubjectProc::addHPContainer(), YACS::HMI::SubjectElementaryNode::addIDSPort(), YACS::HMI::SubjectElementaryNode::addInputPort(), YACS::HMI::SubjectElementaryNode::addODSPort(), YACS::HMI::SubjectElementaryNode::addOutputPort(), YACS::HMI::SubjectServiceNode::associateToComponent(), YACS::HMI::SubjectComponent::associateToContainer(), YACS::HMI::SubjectNode::copy(), YACS::HMI::SubjectComposedNode::createNode(), YACS::HMI::Subject::destroy(), YACS::HMI::SubjectElementaryNode::OrderDataPorts(), YACS::HMI::SubjectNode::putInComposedNode(), YACS::HMI::SubjectNode::reparent(), YACS::HMI::SubjectOptimizerLoop::setAlgorithm(), YACS::HMI::SubjectSwitch::setCase(), YACS::HMI::SubjectServiceNode::setComponentFromCatalog(), YACS::HMI::SubjectWhileLoop::setCondition(), YACS::HMI::SubjectInlineNode::setContainer(), YACS::HMI::SubjectInlineNode::setExecutionMode(), YACS::HMI::SubjectPyFuncNode::setFunctionName(), YACS::HMI::SubjectDataPort::setName(), YACS::HMI::SubjectNode::setName(), YACS::HMI::SubjectContainerBase::setName(), YACS::HMI::SubjectDynParaLoop::setNbBranches(), YACS::HMI::SubjectForLoop::setNbSteps(), YACS::HMI::SubjectInputDataStreamPort::setProperties(), YACS::HMI::SubjectOutputDataStreamPort::setProperties(), YACS::HMI::SubjectNode::setProperties(), YACS::HMI::SubjectContainerBase::setProperties(), YACS::HMI::SubjectComponent::setProperties(), YACS::HMI::SubjectLink::setProperties(), YACS::HMI::SubjectInlineNode::setScript(), YACS::HMI::SubjectSwitch::setSelect(), YACS::HMI::SubjectInputPort::setValue(), YACS::HMI::SubjectOutputPort::setValue(), YACS::HMI::SubjectDataPort::tryCreateLink(), and YACS::HMI::SubjectNode::tryCreateLink().

◆ executeSubOnly()

bool Command::executeSubOnly ( )
virtual

execute only sub commands in a reverse action

for undo of commandDestroy, only sub commands of commandDestroy must be executed, via subcommand->reverse(false)

Definition at line 105 of file commands.cxx.

106{
107 bool ret=true;
108 if (! _subCommands.empty())
109 {
110 for (int i=0; i<_subCommands.size(); i++)
111 {
112 ret =_subCommands[i]->reverse(false);
113 if (!ret) break;
114 }
115 }
116 return ret;
117}

References _subCommands, and yacsorb.CORBAEngineTest::i.

◆ isNormalReverse()

bool YACS::HMI::Command::isNormalReverse ( )
inline

Definition at line 48 of file commands.hxx.

48{ return _normalReverse; };

References _normalReverse.

◆ localExecute()

virtual bool YACS::HMI::Command::localExecute ( )
protectedpure virtual

Implemented in YACS::HMI::CommandAddNodeFromCatalog, YACS::HMI::CommandReparentNode, YACS::HMI::CommandPutInComposedNode, YACS::HMI::CommandCopyNode, YACS::HMI::CommandRenameNode, YACS::HMI::CommandRenameContainer, YACS::HMI::CommandRenameInDataPort, YACS::HMI::CommandRenameOutDataPort, YACS::HMI::CommandAddDataTypeFromCatalog, YACS::HMI::CommandAddInputPortFromCatalog, YACS::HMI::CommandAddOutputPortFromCatalog, YACS::HMI::CommandAddIDSPortFromCatalog, YACS::HMI::CommandAddODSPortFromCatalog, YACS::HMI::CommandOrderInputPorts, YACS::HMI::CommandOrderOutputPorts, YACS::HMI::CommandSetInPortValue, YACS::HMI::CommandSetOutPortValue, YACS::HMI::CommandSetSwitchSelect, YACS::HMI::CommandSetSwitchCase, YACS::HMI::CommandSetForLoopSteps, YACS::HMI::CommandSetWhileCondition, YACS::HMI::CommandSetForEachBranch, YACS::HMI::CommandSetAlgo, YACS::HMI::CommandAddLink, YACS::HMI::CommandAddControlLink, YACS::HMI::CommandAddContainerBase, YACS::HMI::CommandSetContainerProperties, YACS::HMI::CommandSetNodeProperties, YACS::HMI::CommandSetComponentInstanceProperties, YACS::HMI::CommandSetDSPortProperties, YACS::HMI::CommandSetLinkProperties, YACS::HMI::CommandSetFuncNodeFunctionName, YACS::HMI::CommandSetInlineNodeScript, YACS::HMI::CommandAddComponentInstance, YACS::HMI::CommandSetExecutionMode, YACS::HMI::CommandSetContainer, YACS::HMI::CommandAssociateComponentToContainer, YACS::HMI::CommandAssociateServiceToComponent, YACS::HMI::CommandAddComponentFromCatalog, and YACS::HMI::CommandDestroy.

Referenced by execute(), and reverse().

◆ localReverse()

virtual bool YACS::HMI::Command::localReverse ( )
protectedpure virtual

Implemented in YACS::HMI::CommandAddNodeFromCatalog, YACS::HMI::CommandReparentNode, YACS::HMI::CommandPutInComposedNode, YACS::HMI::CommandCopyNode, YACS::HMI::CommandRenameNode, YACS::HMI::CommandRenameContainer, YACS::HMI::CommandRenameInDataPort, YACS::HMI::CommandRenameOutDataPort, YACS::HMI::CommandAddDataTypeFromCatalog, YACS::HMI::CommandAddInputPortFromCatalog, YACS::HMI::CommandAddOutputPortFromCatalog, YACS::HMI::CommandAddIDSPortFromCatalog, YACS::HMI::CommandAddODSPortFromCatalog, YACS::HMI::CommandOrderInputPorts, YACS::HMI::CommandOrderOutputPorts, YACS::HMI::CommandSetInPortValue, YACS::HMI::CommandSetOutPortValue, YACS::HMI::CommandSetSwitchSelect, YACS::HMI::CommandSetSwitchCase, YACS::HMI::CommandSetForLoopSteps, YACS::HMI::CommandSetWhileCondition, YACS::HMI::CommandSetForEachBranch, YACS::HMI::CommandSetAlgo, YACS::HMI::CommandAddLink, YACS::HMI::CommandAddControlLink, YACS::HMI::CommandAddContainerBase, YACS::HMI::CommandSetContainerProperties, YACS::HMI::CommandSetNodeProperties, YACS::HMI::CommandSetComponentInstanceProperties, YACS::HMI::CommandSetDSPortProperties, YACS::HMI::CommandSetLinkProperties, YACS::HMI::CommandSetFuncNodeFunctionName, YACS::HMI::CommandSetInlineNodeScript, YACS::HMI::CommandAddComponentInstance, YACS::HMI::CommandSetExecutionMode, YACS::HMI::CommandSetContainer, YACS::HMI::CommandAssociateComponentToContainer, YACS::HMI::CommandAssociateServiceToComponent, YACS::HMI::CommandAddComponentFromCatalog, and YACS::HMI::CommandDestroy.

Referenced by reverse().

◆ recursiveDump()

std::string Command::recursiveDump ( int  level = 0)

Definition at line 124 of file commands.cxx.

125{
126 string prefix = "";
127 for (int i=0; i<level; i++) prefix += " ";
128 string ret = prefix + dump() + "\n";
129 for (int i=0; i<_subCommands.size(); i++)
130 ret += _subCommands[i]->recursiveDump(level+1);
131 return ret;
132}
std::string recursiveDump(int level=0)
Definition: commands.cxx:124
virtual std::string dump()
Definition: commands.cxx:119

References _subCommands, dump(), yacsorb.CORBAEngineTest::i, and recursiveDump().

Referenced by recursiveDump().

◆ reverse()

bool Command::reverse ( bool  isNormal = true)
virtual

Reverse action: undo.

Recursive reverse of sub commands then local action

Parameters
isNormaltrue for ordinary command, false for command Destroy

Definition at line 79 of file commands.cxx.

80{
81 bool ret=true;
82 if (! _subCommands.empty())
83 {
84 for (int i=0; i<_subCommands.size(); i++)
85 {
86 ret =_subCommands[i]->reverse(isNormal);
87 if (!ret) break;
88 }
89 }
90 if (ret)
91 {
92 if (isNormal) // true for all commands but commandDestroy
93 ret = localReverse();
94 else
95 ret = localExecute(); // subCommand of command Destroy
96 }
97 return ret;
98}
virtual bool localReverse()=0

References _subCommands, yacsorb.CORBAEngineTest::i, localExecute(), and localReverse().

Member Data Documentation

◆ _normalReverse

bool YACS::HMI::Command::_normalReverse
protected

◆ _subCommands

std::vector<Command*> YACS::HMI::Command::_subCommands
protected

Definition at line 52 of file commands.hxx.

Referenced by addSubCommand(), Command(), execute(), executeSubOnly(), recursiveDump(), and reverse().


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