Version: 9.15.0
YACS::HMI::CommandAddComponentFromCatalog Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandAddComponentFromCatalog:
Collaboration diagram for YACS::HMI::CommandAddComponentFromCatalog:

Public Member Functions

 CommandAddComponentFromCatalog (YACS::ENGINE::Catalog *catalog, std::string position, std::string compo, std::string service)
 
- 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

YACS::ENGINE::Catalog_catalog
 
std::string _position
 
std::string _compo
 
std::string _service
 
std::string _nameInProc
 
bool _createdInstance
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 738 of file commandsProc.hxx.

Constructor & Destructor Documentation

◆ CommandAddComponentFromCatalog()

CommandAddComponentFromCatalog::CommandAddComponentFromCatalog ( YACS::ENGINE::Catalog catalog,
std::string  position,
std::string  compo,
std::string  service 
)

Definition at line 4201 of file commandsProc.cxx.

4205  : Command(), _catalog(catalog), _position(position), _compo(compo), _service(service)
4206 {
4207  DEBTRACE("CommandAddComponentFromCatalog::CommandAddComponentFromCatalog " << position << " " << compo << " " << service);
4208  _nameInProc="";
4209  _createdInstance = false;
4210 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31

References _createdInstance, _nameInProc, and DEBTRACE.

Member Function Documentation

◆ dump()

std::string CommandAddComponentFromCatalog::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 4212 of file commandsProc.cxx.

4213 {
4214  string ret = "CommandAddComponentFromCatalog " + _position + " " + _compo + " " + _service;
4215  return ret;
4216 }

References _compo, _position, and _service.

◆ localExecute()

bool CommandAddComponentFromCatalog::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4218 of file commandsProc.cxx.

4219 {
4220  DEBTRACE("CommandAddComponentFromCatalog::localExecute");
4221  try
4222  {
4223  DEBTRACE("_nameInProc: " << _nameInProc);
4224  Proc* proc = GuiContext::getCurrent()->getProc();
4225  Node* node = proc;
4226  if (!_position.empty()) node = proc->getChildByName(_position);
4227  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4229  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4230  YASSERT(ssnode);
4231  if (_catalog->_componentMap.count(_compo))
4232  {
4234  if (compodef->_serviceMap.count(_service))
4235  {
4236  Proc* proc = GuiContext::getCurrent()->getProc();
4237  ComponentInstance *instance =ssnode->_serviceNode->getComponent();
4238  YASSERT(instance);
4239  SubjectComponent* subCompo = 0;
4240  _createdInstance = false;
4241  if(!GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
4242  {
4243  _createdInstance = true;
4244  //automatic rename of the component instance by the proc on first execute
4245  DEBTRACE("name given to proc:" << _nameInProc);
4246  proc->addComponentInstance(instance,_nameInProc, true);
4247  _nameInProc= instance->getInstanceName();
4248  DEBTRACE("name given by proc:" << _nameInProc);
4249  subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
4250  }
4251  else
4252  subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
4253  YASSERT(subCompo);
4254  ssnode->addSubjectReference(subCompo);
4255  YASSERT(! ssnode->_subRefComponent);
4256  ssnode->_subRefComponent = subCompo->attachService(ssnode);
4257  }
4258  }
4259  return true;
4260  }
4261  catch (Exception& ex)
4262  {
4263  DEBTRACE("CommandAddComponentFromCatalog::localExecute() : " << ex.what());
4264  setErrorMsg(ex);
4265  return false;
4266  }
4267 }
#define YASSERT(val)
YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort.
Definition: YacsTrace.hxx:59
std::map< std::string, ComponentDefinition * > _componentMap
Definition: Catalog.hxx:50
Base class for component definition.
std::map< std::string, ServiceNode * > _serviceMap
Base class for all component instances.
const std::string & getInstanceName() 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
virtual void addComponentInstance(ComponentInstance *inst, const std::string &name="", bool resetCtr=false)
Add a ComponentInstance into componentInstanceMap.
Definition: Proc.cxx:526
virtual ComponentInstance * getComponent()
Return the associated component instance.
YACS::HMI::SubjectProc * getSubjectProc()
Definition: guiContext.hxx:52
YACS::ENGINE::Proc * getProc()
Definition: guiContext.hxx:50
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
virtual SubjectReference * attachService(SubjectServiceNode *service)
SubjectComponent * addSubjectComponent(YACS::ENGINE::ComponentInstance *compo)
SubjectReference * _subRefComponent
YACS::ENGINE::ServiceNode * _serviceNode
virtual void addSubjectReference(Subject *ref)
void setErrorMsg(YACS::Exception &ex)

References _catalog, _compo, YACS::ENGINE::Catalog::_componentMap, _createdInstance, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectNode, _nameInProc, _position, _service, YACS::ENGINE::ComponentDefinition::_serviceMap, YACS::HMI::SubjectServiceNode::_serviceNode, YACS::HMI::SubjectServiceNode::_subRefComponent, YACS::ENGINE::Proc::addComponentInstance(), YACS::HMI::SubjectProc::addSubjectComponent(), YACS::HMI::SubjectServiceNode::addSubjectReference(), YACS::HMI::SubjectComponent::attachService(), DEBTRACE, testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ServiceNode::getComponent(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComponentInstance::getInstanceName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::GuiContext::getSubjectProc(), setErrorMsg(), and YASSERT.

◆ localReverse()

bool CommandAddComponentFromCatalog::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 4269 of file commandsProc.cxx.

4270 {
4271  DEBTRACE("CommandAddComponentFromCatalog::localReverse");
4272  try
4273  {
4274  Proc* proc = GuiContext::getCurrent()->getProc();
4275  Node* node = proc;
4276  if (!_position.empty()) node = proc->getChildByName(_position);
4277  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4279  SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4280  YASSERT(ssnode);
4281 
4282  DEBTRACE("_nameInProc: " << _nameInProc);
4285  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4287 
4288  subCompo->detachService(ssnode);
4289  if (subCompo->hasServices())
4290  throw YACS::Exception("Component instance with services attached, not removed");
4291  Container *cont = compo->getContainer();
4292  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4294  subcont->detachComponent(subCompo);
4295  //remove componentInstance from proc, from context
4296  if (_createdInstance)
4297  {
4299  proc->removeComponentInstance(compo);
4300  }
4301  DEBTRACE("_nameInProc: " << _nameInProc);
4302  return true;
4303  }
4304  catch (Exception& ex)
4305  {
4306  DEBTRACE("CommandAddComponentFromCatalog::localReverse() : " << ex.what());
4307  setErrorMsg(ex);
4308  return false;
4309  }
4310 }
virtual void removeComponentInstance(ComponentInstance *inst)
Remove a componentInstance from the componentInstanceMap.
Definition: Proc.cxx:566
std::map< std::string, ComponentInstance * > componentInstanceMap
Definition: Proc.hxx:92
std::map< YACS::ENGINE::Container *, YACS::HMI::SubjectContainerBase * > _mapOfSubjectContainer
Definition: guiContext.hxx:75
virtual void detachService(SubjectServiceNode *service)
virtual void detachComponent(SubjectComponent *component)

References _createdInstance, YACS::HMI::GuiContext::_mapOfSubjectComponent, YACS::HMI::GuiContext::_mapOfSubjectContainer, YACS::HMI::GuiContext::_mapOfSubjectNode, _nameInProc, _position, YACS::ENGINE::Proc::componentInstanceMap, DEBTRACE, YACS::HMI::SubjectContainerBase::detachComponent(), YACS::HMI::SubjectComponent::detachService(), testCppPluginInvokation::ex, YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComponentInstance::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::SubjectComponent::hasServices(), YACS::ENGINE::Proc::removeComponentInstance(), setErrorMsg(), and YASSERT.

Member Data Documentation

◆ _catalog

YACS::ENGINE::Catalog* YACS::HMI::CommandAddComponentFromCatalog::_catalog
protected

Definition at line 749 of file commandsProc.hxx.

Referenced by localExecute().

◆ _compo

std::string YACS::HMI::CommandAddComponentFromCatalog::_compo
protected

Definition at line 751 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

◆ _createdInstance

bool YACS::HMI::CommandAddComponentFromCatalog::_createdInstance
protected

Definition at line 754 of file commandsProc.hxx.

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

◆ _nameInProc

std::string YACS::HMI::CommandAddComponentFromCatalog::_nameInProc
protected

Definition at line 753 of file commandsProc.hxx.

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

◆ _position

std::string YACS::HMI::CommandAddComponentFromCatalog::_position
protected

Definition at line 750 of file commandsProc.hxx.

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

◆ _service

std::string YACS::HMI::CommandAddComponentFromCatalog::_service
protected

Definition at line 752 of file commandsProc.hxx.

Referenced by dump(), and localExecute().


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