Version: 8.3.0
YACS::HMI::CommandAssociateServiceToComponent Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandAssociateServiceToComponent:
Collaboration diagram for YACS::HMI::CommandAssociateServiceToComponent:

Public Member Functions

 CommandAssociateServiceToComponent (std::string service, std::string instanceName)
 
- 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 _service
 
std::string _instanceName
 
std::string _oldInstance
 
std::string _oldcont
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 723 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandAssociateServiceToComponent::CommandAssociateServiceToComponent ( std::string  service,
std::string  instanceName 
)

Definition at line 4075 of file commandsProc.cxx.

References _oldInstance, and DEBTRACE.

4077  : Command(), _service(service), _instanceName(instanceName)
4078 {
4079  DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4080  _oldInstance="";
4081 }

Member Function Documentation

std::string CommandAssociateServiceToComponent::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 4083 of file commandsProc.cxx.

References _instanceName, _service, and PMMLBasicsTestLauncher::ret.

4084 {
4085  string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4086  return ret;
4087 }
bool CommandAssociateServiceToComponent::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4089 of file commandsProc.cxx.

References _instanceName, YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectNode, _oldcont, _oldInstance, _service, YACS::HMI::SubjectServiceNode::_subRefComponent, YACS::ENGINE::Proc::componentInstanceMap, DEBTRACE, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::SubjectComponent::getComponent(), YACS::ENGINE::ComponentInstance::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComposedNode::getName(), YACS::ENGINE::Container::getName(), YACS::HMI::SubjectComponent::getName(), YACS::HMI::Subject::getParent(), YACS::HMI::GuiContext::getProc(), setErrorMsg(), YACS::Exception::what(), and YASSERT.

4090 {
4091  DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4092  try
4093  {
4094  Proc* proc = GuiContext::getCurrent()->getProc();
4095  if (_service == proc->getName()) return false; // proc is not an elementary node
4096  Node* node = proc->getChildByName(_service);
4097  if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4098  {
4099  if (proc->componentInstanceMap.count(_instanceName))
4100  {
4103  service->setComponent(compo);
4104 
4105  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4107  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4108  YASSERT(ssnode);
4109  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4111  snode->addSubjectReference(subCompo);
4112  if (ssnode->_subRefComponent)
4113  {
4114  SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4115  YASSERT(oldcomp);
4116  _oldInstance = oldcomp->getName();
4117  _oldcont = oldcomp->getComponent()->getContainer()->getName();
4118  subCompo->moveService(ssnode->_subRefComponent);
4119  }
4120  else
4121  ssnode->_subRefComponent = subCompo->attachService(ssnode);
4122 
4123  return true;
4124  }
4125  else
4126  GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4127  }
4128  else
4129  GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4130  return false;
4131  }
4132  catch (Exception& ex)
4133  {
4134  DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4135  setErrorMsg(ex);
4136  return false;
4137  }
4138 }
bool CommandAssociateServiceToComponent::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4140 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectNode, _oldcont, _oldInstance, _service, YACS::HMI::SubjectServiceNode::_subRefComponent, YACS::ENGINE::Proc::addComponentInstance(), YACS::HMI::SubjectProc::addSubjectComponent(), YACS::ENGINE::ComponentInstance::cloneAlways(), YACS::ENGINE::Proc::componentInstanceMap, YACS::ENGINE::Proc::containerMap, DEBTRACE, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::GuiContext::getSubjectProc(), YACS::ENGINE::ComponentInstance::setContainer(), setErrorMsg(), YACS::ENGINE::ComponentInstance::setName(), YACS::Exception::what(), and YASSERT.

4141 {
4142  DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4143  try
4144  {
4145  Proc* proc = GuiContext::getCurrent()->getProc();
4146  if (_service == proc->getName()) return false; // proc is not an elementary node
4147  Node* node = proc->getChildByName(_service);
4148  if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4149  {
4150  ComponentInstance *compo;
4151  if (!proc->componentInstanceMap.count(_oldInstance))
4152  {
4153  //component instance does not exist anymore recreate it
4154  ComponentInstance *oldcompo = service->getComponent();
4155  compo = oldcompo->cloneAlways();
4156  compo->setName(_oldInstance);
4157  proc->addComponentInstance(compo, _oldInstance);
4158  Container *cont = proc->containerMap[_oldcont];
4159  compo->setContainer(cont);
4161  sproc->addSubjectComponent(compo);
4162  }
4163  else
4164  {
4165  compo = proc->componentInstanceMap[_oldInstance];
4166  }
4167 
4169  service->setComponent(compo);
4170 
4171  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4173  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4174  YASSERT(ssnode);
4175  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4177  snode->addSubjectReference(subCompo);
4178  if (ssnode->_subRefComponent)
4179  subCompo->moveService(ssnode->_subRefComponent);
4180  else
4181  ssnode->_subRefComponent = subCompo->attachService(ssnode);
4182 
4183  return true;
4184  }
4185  else
4186  GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4187  return false;
4188  }
4189  catch (Exception& ex)
4190  {
4191  DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4192  setErrorMsg(ex);
4193  return false;
4194  }
4195 }

Member Data Documentation

std::string YACS::HMI::CommandAssociateServiceToComponent::_instanceName
protected

Definition at line 733 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

std::string YACS::HMI::CommandAssociateServiceToComponent::_oldcont
protected

Definition at line 735 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

std::string YACS::HMI::CommandAssociateServiceToComponent::_oldInstance
protected
std::string YACS::HMI::CommandAssociateServiceToComponent::_service
protected

Definition at line 732 of file commandsProc.hxx.

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


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