Version: 9.15.0
YACS::HMI::CommandAssociateComponentToContainer Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandAssociateComponentToContainer:
Collaboration diagram for YACS::HMI::CommandAssociateComponentToContainer:

Public Member Functions

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

Detailed Description

Definition at line 709 of file commandsProc.hxx.

Constructor & Destructor Documentation

◆ CommandAssociateComponentToContainer()

CommandAssociateComponentToContainer::CommandAssociateComponentToContainer ( std::string  instanceName,
std::string  container 
)

Definition at line 3973 of file commandsProc.cxx.

3975  : Command(), _container(container),_instanceName(instanceName)
3976 {
3977  DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer " << instanceName << " " << container);
3978  _oldcont = "DefaultContainer";
3979 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _oldcont, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandAssociateComponentToContainer::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 3981 of file commandsProc.cxx.

3982 {
3983  string ret ="CommandAssociateComponentToContainer " + _container + " " + _instanceName;
3984  return ret;
3985 }

References _container, and _instanceName.

◆ localExecute()

bool CommandAssociateComponentToContainer::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 3987 of file commandsProc.cxx.

3988 {
3989  DEBTRACE("CommandAssociateComponentToContainer::localExecute");
3990  try
3991  {
3992  Proc* proc = GuiContext::getCurrent()->getProc();
3993  if (proc->containerMap.count(_container))
3994  {
3995  Container *cont = proc->containerMap[_container];
3996  if (proc->componentInstanceMap.count(_instanceName))
3997  {
4000  if (compo->getContainer())
4001  _oldcont = compo->getContainer()->getName();
4002  compo->setContainer(cont);
4003 
4004  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4006  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4008  scomp->addSubjectReference(subcont);
4009  if (scomp->_subRefContainer)
4010  subcont->moveComponent(scomp->_subRefContainer);
4011  else
4012  scomp->_subRefContainer = subcont->attachComponent(scomp);
4013  scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4014  return true;
4015  }
4016  else
4017  GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4018  }
4019  else
4020  GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
4021  return false;
4022  }
4023  catch (Exception& ex)
4024  {
4025  DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
4026  setErrorMsg(ex);
4027  return false;
4028  }
4029 }
#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.
virtual bool setContainer(Container *cont)
virtual std::string getName() const
Definition: Container.hxx:81
Base class for all schema objects.
Definition: Proc.hxx:44
std::map< std::string, Container * > containerMap
Definition: Proc.hxx:91
std::map< std::string, ComponentInstance * > componentInstanceMap
Definition: Proc.hxx:92
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
std::string _lastErrorMessage
Definition: guiContext.hxx:79
std::map< YACS::ENGINE::Container *, YACS::HMI::SubjectContainerBase * > _mapOfSubjectContainer
Definition: guiContext.hxx:75
std::map< YACS::ENGINE::ComponentInstance *, YACS::HMI::SubjectComponent * > _mapOfSubjectComponent
Definition: guiContext.hxx:74
static GuiContext * getCurrent()
Definition: guiContext.hxx:67
SubjectReference * _subRefContainer
virtual void notifyServicesChange(GuiEvent event, int type, Subject *son)
virtual void moveComponent(SubjectReference *reference)
virtual SubjectReference * attachComponent(SubjectComponent *component)
virtual void addSubjectReference(Subject *ref)
void setErrorMsg(YACS::Exception &ex)

References _container, _instanceName, YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectContainer, _oldcont, YACS::HMI::SubjectComponent::_subRefContainer, YACS::HMI::Subject::addSubjectReference(), YACS::HMI::ASSOCIATE, YACS::HMI::SubjectContainerBase::attachComponent(), YACS::ENGINE::Proc::componentInstanceMap, YACS::HMI::CONTAINER, YACS::ENGINE::Proc::containerMap, DEBTRACE, testCppPluginInvokation::ex, YACS::ENGINE::ComponentInstance::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Container::getName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::SubjectContainerBase::moveComponent(), YACS::HMI::SubjectComponent::notifyServicesChange(), YACS::ENGINE::ComponentInstance::setContainer(), setErrorMsg(), and YASSERT.

◆ localReverse()

bool CommandAssociateComponentToContainer::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4031 of file commandsProc.cxx.

4032 {
4033  DEBTRACE("CommandAssociateComponentToContainer::localReverse");
4034  try
4035  {
4036  if (_oldcont == _container) return true;
4037  Proc* proc = GuiContext::getCurrent()->getProc();
4038  if (proc->containerMap.count(_oldcont))
4039  {
4040  Container *cont = proc->containerMap[_oldcont];
4041  if (proc->componentInstanceMap.count(_instanceName))
4042  {
4045  compo->setContainer(cont);
4046 
4047  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4049  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4051  scomp->addSubjectReference(subcont);
4052  if (scomp->_subRefContainer)
4053  subcont->moveComponent(scomp->_subRefContainer);
4054  else
4055  scomp->_subRefContainer = subcont->attachComponent(scomp);
4056  scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4057  return true;
4058  }
4059  else
4060  GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4061  }
4062  else
4063  GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
4064  return false;
4065  }
4066  catch (Exception& ex)
4067  {
4068  DEBTRACE("CommandAssociateComponentToContainer::localReverse() : " << ex.what());
4069  setErrorMsg(ex);
4070  return false;
4071  }
4072  return true;
4073 }

References _container, _instanceName, YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectContainer, _oldcont, YACS::HMI::SubjectComponent::_subRefContainer, YACS::HMI::Subject::addSubjectReference(), YACS::HMI::ASSOCIATE, YACS::HMI::SubjectContainerBase::attachComponent(), YACS::ENGINE::Proc::componentInstanceMap, YACS::HMI::CONTAINER, YACS::ENGINE::Proc::containerMap, DEBTRACE, testCppPluginInvokation::ex, YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::SubjectContainerBase::moveComponent(), YACS::HMI::SubjectComponent::notifyServicesChange(), YACS::ENGINE::ComponentInstance::setContainer(), setErrorMsg(), and YASSERT.

Member Data Documentation

◆ _container

std::string YACS::HMI::CommandAssociateComponentToContainer::_container
protected

Definition at line 718 of file commandsProc.hxx.

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

◆ _instanceName

std::string YACS::HMI::CommandAssociateComponentToContainer::_instanceName
protected

Definition at line 719 of file commandsProc.hxx.

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

◆ _oldcont

std::string YACS::HMI::CommandAssociateComponentToContainer::_oldcont
protected

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