Version: 9.15.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::CommandAssociateServiceToComponent ( std::string  service,
std::string  instanceName 
)

Definition at line 4077 of file commandsProc.cxx.

4079  : Command(), _service(service), _instanceName(instanceName)
4080 {
4081  DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4082  _oldInstance="";
4083 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _oldInstance, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandAssociateServiceToComponent::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 4085 of file commandsProc.cxx.

4086 {
4087  string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4088  return ret;
4089 }

References _instanceName, and _service.

◆ localExecute()

bool CommandAssociateServiceToComponent::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4091 of file commandsProc.cxx.

4092 {
4093  DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4094  try
4095  {
4096  Proc* proc = GuiContext::getCurrent()->getProc();
4097  if (_service == proc->getName()) return false; // proc is not an elementary node
4098  Node* node = proc->getChildByName(_service);
4099  if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4100  {
4101  if (proc->componentInstanceMap.count(_instanceName))
4102  {
4105  service->setComponent(compo);
4106 
4107  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4109  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4110  YASSERT(ssnode);
4111  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4113  snode->addSubjectReference(subCompo);
4114  if (ssnode->_subRefComponent)
4115  {
4116  SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4117  YASSERT(oldcomp);
4118  _oldInstance = oldcomp->getName();
4119  _oldcont = oldcomp->getComponent()->getContainer()->getName();
4120  subCompo->moveService(ssnode->_subRefComponent);
4121  }
4122  else
4123  ssnode->_subRefComponent = subCompo->attachService(ssnode);
4124 
4125  return true;
4126  }
4127  else
4128  GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4129  }
4130  else
4131  GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4132  return false;
4133  }
4134  catch (Exception& ex)
4135  {
4136  DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4137  setErrorMsg(ex);
4138  return false;
4139  }
4140 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
Base class for all component instances.
Node * getChildByName(const std::string &name) const
std::string getName() const
virtual std::string getName() const
Definition: Container.hxx:81
Base class for all nodes.
Definition: Node.hxx:70
Base class for all schema objects.
Definition: Proc.hxx:44
std::map< std::string, ComponentInstance * > componentInstanceMap
Definition: Proc.hxx:92
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
std::string _lastErrorMessage
Definition: guiContext.hxx:79
std::map< YACS::ENGINE::ComponentInstance *, YACS::HMI::SubjectComponent * > _mapOfSubjectComponent
Definition: guiContext.hxx:74
std::map< YACS::ENGINE::Node *, YACS::HMI::SubjectNode * > _mapOfSubjectNode
Definition: guiContext.hxx:68
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
YACS::ENGINE::ComponentInstance * getComponent() const
virtual SubjectReference * attachService(SubjectServiceNode *service)
virtual std::string getName()
virtual void moveService(SubjectReference *reference)
SubjectReference * _subRefComponent
virtual Subject * getParent()
virtual void addSubjectReference(Subject *ref)
void setErrorMsg(YACS::Exception &ex)

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

◆ localReverse()

bool CommandAssociateServiceToComponent::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4142 of file commandsProc.cxx.

4143 {
4144  DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4145  try
4146  {
4147  Proc* proc = GuiContext::getCurrent()->getProc();
4148  if (_service == proc->getName()) return false; // proc is not an elementary node
4149  Node* node = proc->getChildByName(_service);
4150  if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4151  {
4152  ComponentInstance *compo;
4153  if (!proc->componentInstanceMap.count(_oldInstance))
4154  {
4155  //component instance does not exist anymore recreate it
4156  ComponentInstance *oldcompo = service->getComponent();
4157  compo = oldcompo->cloneAlways();
4158  compo->setName(_oldInstance);
4159  proc->addComponentInstance(compo, _oldInstance);
4160  Container *cont = proc->containerMap[_oldcont];
4161  compo->setContainer(cont);
4163  sproc->addSubjectComponent(compo);
4164  }
4165  else
4166  {
4167  compo = proc->componentInstanceMap[_oldInstance];
4168  }
4169 
4171  service->setComponent(compo);
4172 
4173  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4175  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4176  YASSERT(ssnode);
4177  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4179  snode->addSubjectReference(subCompo);
4180  if (ssnode->_subRefComponent)
4181  subCompo->moveService(ssnode->_subRefComponent);
4182  else
4183  ssnode->_subRefComponent = subCompo->attachService(ssnode);
4184 
4185  return true;
4186  }
4187  else
4188  GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4189  return false;
4190  }
4191  catch (Exception& ex)
4192  {
4193  DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4194  setErrorMsg(ex);
4195  return false;
4196  }
4197 }
virtual bool setContainer(Container *cont)
void setName(const std::string &name)
virtual ComponentInstance * cloneAlways() const =0
std::map< std::string, Container * > containerMap
Definition: Proc.hxx:91
virtual void addComponentInstance(ComponentInstance *inst, const std::string &name="", bool resetCtr=false)
Add a ComponentInstance into componentInstanceMap.
Definition: Proc.cxx:526
YACS::HMI::SubjectProc * getSubjectProc()
Definition: guiContext.hxx:52
SubjectComponent * addSubjectComponent(YACS::ENGINE::ComponentInstance *compo)

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::HMI::Subject::addSubjectReference(), YACS::HMI::SubjectComponent::attachService(), YACS::ENGINE::ComponentInstance::cloneAlways(), YACS::ENGINE::Proc::componentInstanceMap, YACS::ENGINE::Proc::containerMap, DEBTRACE, testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComposedNode::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::GuiContext::getSubjectProc(), YACS::HMI::SubjectComponent::moveService(), YACS::ENGINE::ComponentInstance::setContainer(), setErrorMsg(), YACS::ENGINE::ComponentInstance::setName(), and YASSERT.

Member Data Documentation

◆ _instanceName

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

Definition at line 733 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

◆ _oldcont

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

Definition at line 735 of file commandsProc.hxx.

Referenced by localExecute(), and localReverse().

◆ _oldInstance

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

◆ _service

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: