Version: 9.16.0
YACS::HMI::CommandSetSwitchCase Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandSetSwitchCase:
Collaboration diagram for YACS::HMI::CommandSetSwitchCase:

Public Member Functions

 CommandSetSwitchCase (std::string aSwitch, std::string node, std::string value)
 
- 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 _switch
 
std::string _node
 
std::string _oldNode
 
std::string _value
 
int _oldValue
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 425 of file commandsProc.hxx.

Constructor & Destructor Documentation

◆ CommandSetSwitchCase()

CommandSetSwitchCase::CommandSetSwitchCase ( std::string  aSwitch,
std::string  node,
std::string  value 
)

Definition at line 2501 of file commandsProc.cxx.

2504 : Command(), _switch(aSwitch), _node(node), _value(value)
2505{
2506 DEBTRACE("CommandSetSwitchCase::CommandSetSwitchCase");
2507 _oldValue = 0;
2508 _oldNode = "";
2509}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _oldNode, _oldValue, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandSetSwitchCase::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 2511 of file commandsProc.cxx.

2512{
2513 string ret ="CommandSetSwitchCase " + _switch + " " + _node + " " + _value;
2514 return ret;
2515}

References _node, _switch, and _value.

◆ localExecute()

bool CommandSetSwitchCase::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2517 of file commandsProc.cxx.

2518{
2519 DEBTRACE("CommandSetSwitchCase::localExecute");
2520 try
2521 {
2522 DEBTRACE("CommandSetSwitchCase::localExecute");
2523 Proc* proc = GuiContext::getCurrent()->getProc();
2524 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2525 Node* node = proc->getChildByName(_node);
2526 int val = atoi(_value.c_str());
2527 if (aSwitch->edGetNode(val))
2528 {
2529 throw YACS::Exception("Set Switch Case impossible: value already used");
2530 }
2531 int oldVal = aSwitch->getRankOfNode(node);
2532 aSwitch->edChangeCase(oldVal,val);
2533 _oldValue = oldVal;
2534 _oldNode = proc->getChildName(node);
2535 DEBTRACE("CommandSetSwitchCase::localExecute OK " << val);
2536 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2539 ssw->update(SETCASE, val, snode);
2540 snode->recursiveUpdate(RENAME, 0, snode);
2541 return true;
2542 }
2543 catch (Exception& ex)
2544 {
2545 DEBTRACE("CommandSetSwitchCase::localExecute() : " << ex.what());
2546 setErrorMsg(ex);
2547 return false;
2548 }
2549}
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
std::string getChildName(const Node *node) const
Node * getChildByName(const std::string &name) const
Base class for all nodes.
Definition: Node.hxx:70
Base class for all schema objects.
Definition: Proc.hxx:44
Control node that emulates the C switch.
Definition: Switch.hxx:85
Node * edGetNode(int caseId)
Definition: Switch.cxx:527
void edChangeCase(int oldCase, int newCase)
Change the case of a node.
Definition: Switch.cxx:575
int getRankOfNode(Node *node) const
Definition: Switch.cxx:752
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
virtual void update(GuiEvent event, int type, Subject *son)
virtual void recursiveUpdate(GuiEvent event, int type, Subject *son)
void setErrorMsg(YACS::Exception &ex)

References YACS::HMI::GuiContext::_mapOfSubjectNode, _node, _oldNode, _oldValue, _switch, _value, DEBTRACE, YACS::ENGINE::Switch::edChangeCase(), YACS::ENGINE::Switch::edGetNode(), testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComposedNode::getChildName(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::Switch::getRankOfNode(), YACS::HMI::SubjectNode::recursiveUpdate(), YACS::HMI::RENAME, YACS::HMI::SETCASE, setErrorMsg(), YACS::HMI::SubjectNode::update(), and YASSERT.

◆ localReverse()

bool CommandSetSwitchCase::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 2551 of file commandsProc.cxx.

2552{
2553 DEBTRACE("CommandSetSwitchCase::localReverse");
2554 try
2555 {
2556 DEBTRACE("CommandSetSwitchCase::localReverse");
2557 Proc* proc = GuiContext::getCurrent()->getProc();
2558 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2559 Node* node = proc->getChildByName(_oldNode);
2560 int val = _oldValue;
2561 if (aSwitch->edGetNode(val))
2562 {
2563 throw YACS::Exception("Set Switch Case impossible: value already used");
2564 }
2565 int oldVal = aSwitch->getRankOfNode(node);
2566 aSwitch->edChangeCase(oldVal,val);
2567 DEBTRACE("CommandSetSwitchCase::localReverse OK " << val);
2568 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2571 ssw->update(SETCASE, val, snode);
2572 snode->recursiveUpdate(RENAME, 0, snode);
2573 return true;
2574 }
2575 catch (Exception& ex)
2576 {
2577 DEBTRACE("CommandSetSwitchCase::localReverse() : " << ex.what());
2578 setErrorMsg(ex);
2579 return false;
2580 }
2581}

References YACS::HMI::GuiContext::_mapOfSubjectNode, _oldNode, _oldValue, _switch, DEBTRACE, YACS::ENGINE::Switch::edChangeCase(), YACS::ENGINE::Switch::edGetNode(), testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getProc(), YACS::ENGINE::Switch::getRankOfNode(), YACS::HMI::SubjectNode::recursiveUpdate(), YACS::HMI::RENAME, YACS::HMI::SETCASE, setErrorMsg(), YACS::HMI::SubjectNode::update(), and YASSERT.

Member Data Documentation

◆ _node

std::string YACS::HMI::CommandSetSwitchCase::_node
protected

Definition at line 436 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

◆ _oldNode

std::string YACS::HMI::CommandSetSwitchCase::_oldNode
protected

Definition at line 437 of file commandsProc.hxx.

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

◆ _oldValue

int YACS::HMI::CommandSetSwitchCase::_oldValue
protected

Definition at line 439 of file commandsProc.hxx.

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

◆ _switch

std::string YACS::HMI::CommandSetSwitchCase::_switch
protected

Definition at line 435 of file commandsProc.hxx.

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

◆ _value

std::string YACS::HMI::CommandSetSwitchCase::_value
protected

Definition at line 438 of file commandsProc.hxx.

Referenced by dump(), and localExecute().


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