Version: 8.3.0
YACS::HMI::SubjectComponent Class Reference

#include <guiObservers.hxx>

Inheritance diagram for YACS::HMI::SubjectComponent:
Collaboration diagram for YACS::HMI::SubjectComponent:

Public Member Functions

 SubjectComponent (YACS::ENGINE::ComponentInstance *component, Subject *parent)
 
virtual ~SubjectComponent ()
 
virtual std::string getName ()
 
virtual void setContainer ()
 
virtual bool associateToContainer (SubjectContainerBase *subcont)
 
virtual SubjectReferenceattachService (SubjectServiceNode *service)
 
virtual void detachService (SubjectServiceNode *service)
 
virtual void moveService (SubjectReference *reference)
 
virtual void removeSubServiceFromSet (SubjectServiceNode *service)
 
virtual bool setProperties (std::map< std::string, std::string > properties)
 
virtual std::map< std::string,
std::string > 
getProperties ()
 
virtual void notifyServicesChange (GuiEvent event, int type, Subject *son)
 
virtual std::pair< std::string,
int > 
getKey ()
 
virtual void clean (Command *command=0)
 
bool hasServices ()
 
void localclean (Command *command=0)
 
YACS::ENGINE::ComponentInstancegetComponent () const
 
virtual TypeOfElem getType ()
 
- Public Member Functions inherited from YACS::HMI::Subject
 Subject (Subject *parent=0)
 
virtual ~Subject ()
 
virtual void attach (GuiObserver *obs)
 
virtual void detach (GuiObserver *obs)
 
virtual void select (bool isSelected)
 
virtual void update (GuiEvent event, int type, Subject *son)
 
virtual bool setName (std::string name)
 
virtual std::vector< std::string > knownProperties ()
 
virtual SubjectgetParent ()
 
virtual void setParent (Subject *son)
 
virtual bool destroy (Subject *son)
 From user action in Ihm, destroy an object. More...
 
virtual void loadChildren ()
 
virtual void loadLinks ()
 
virtual void addSubjectReference (Subject *ref)
 
void localclean (Command *command=0)
 
void registerUndoDestroy ()
 
void askRegisterUndoDestroy ()
 
bool isDestructible ()
 
virtual void setProgress (std::string newProgress)
 
virtual std::string getProgress ()
 
- Public Member Functions inherited from YACS::ENGINE::Observer
virtual void notifyObserver (Node *object, const std::string &event)
 
virtual void notifyObserver2 (Node *object, const std::string &event, void *something)
 
virtual ~Observer ()
 

Public Attributes

SubjectReference_subRefContainer
 

Protected Attributes

int _id
 
YACS::ENGINE::ComponentInstance_compoInst
 
std::set< SubjectServiceNode * > _subServiceSet
 
std::map< SubjectServiceNode
*, SubjectReference * > 
_subReferenceMap
 
- Protected Attributes inherited from YACS::HMI::Subject
std::set< GuiObserver * > _setObs
 
Subject_parent
 
bool _destructible
 
bool _askRegisterUndo
 
std::string _progress
 

Friends

class SubjectNode
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::HMI::Subject
static void erase (Subject *sub, Command *command=0, bool post=false)
 

Detailed Description

Definition at line 460 of file guiObservers.hxx.

Constructor & Destructor Documentation

SubjectComponent::SubjectComponent ( YACS::ENGINE::ComponentInstance component,
Subject parent 
)

Definition at line 4199 of file guiObservers.cxx.

References _compoInst, _subRefContainer, _subReferenceMap, _subServiceSet, and YACS::ENGINE::RefCounter::incrRef().

4200  : Subject(parent), _compoInst(component)
4201 {
4202  _compoInst->incrRef();
4203  _subRefContainer = 0;
4204  _subServiceSet.clear();
4205  _subReferenceMap.clear();
4206 }

Member Function Documentation

bool SubjectComponent::associateToContainer ( SubjectContainerBase subcont)
virtual

Definition at line 4308 of file guiObservers.cxx.

References _compoInst, YACS::HMI::Invocator::add(), DEBTRACE, YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComponentInstance::getInstanceName(), YACS::HMI::GuiContext::getInvoc(), YACS::HMI::SubjectContainerBase::getName(), getName(), and YACS::HMI::GuiContext::isLoading().

Referenced by YACS::HMI::SchemaDirContainersItem::addComponentItem(), YACS::HMI::EditionComponent::changeContainer(), and YACS::HMI::EditionSalomeNode::changeContainer().

4309 {
4310  DEBTRACE("SubjectComponent::associateToContainer " << getName() << " " << subcont->getName());
4313  if (command->execute())
4314  {
4315  if (!GuiContext::getCurrent()->isLoading()) // do not register command when loading a schema
4316  GuiContext::getCurrent()->getInvoc()->add(command);
4317  else delete command;
4318  return true;
4319  }
4320  else delete command;
4321  return false;
4322 }
SubjectReference * SubjectComponent::attachService ( SubjectServiceNode service)
virtual

Definition at line 4324 of file guiObservers.cxx.

References _subReferenceMap, _subServiceSet, YACS::HMI::ADDCHILDREF, DEBTRACE, YACS::HMI::SALOMENODE, and YACS::HMI::Subject::update().

Referenced by YACS::HMI::CommandAddComponentFromCatalog::localExecute(), and YACS::HMI::SubjectServiceNode::setComponent().

4325 {
4326  DEBTRACE("SubjectComponent::attachService");
4327  SubjectReference *son = new SubjectReference(service, this);
4328  _subServiceSet.insert(service);
4329  _subReferenceMap[service] = son;
4330  update(ADDCHILDREF, SALOMENODE, son);
4331  return son;
4332 }
void SubjectComponent::clean ( Command command = 0)
virtual

Clean process prior to delete is redefined in derived classes: a local clean treatment relative to the derived class, then a call to the parent class clean method.

Reimplemented from YACS::HMI::Subject.

Definition at line 4219 of file guiObservers.cxx.

References YACS::HMI::Subject::_askRegisterUndo, YACS::HMI::Subject::clean(), localclean(), and YACS::HMI::Subject::registerUndoDestroy().

4220 {
4221  if (_askRegisterUndo)
4222  {
4223  _askRegisterUndo = false;
4225  }
4226  localclean(command);
4227  Subject::clean(command);
4228 }
void SubjectComponent::detachService ( SubjectServiceNode service)
virtual

Definition at line 4334 of file guiObservers.cxx.

References _subReferenceMap, _subServiceSet, DEBTRACE, YACS::HMI::Subject::erase(), YACS::HMI::REMOVECHILDREF, YACS::HMI::SubjectServiceNode::removeSubRefComponent(), YACS::HMI::SALOMENODE, YACS::HMI::Subject::update(), and YASSERT.

4335 {
4336  DEBTRACE("SubjectComponent::detachService");
4337  YASSERT(_subReferenceMap.count(service));
4338  SubjectReference *reference = _subReferenceMap[service];
4339  update(REMOVECHILDREF, SALOMENODE, reference);
4340  _subServiceSet.erase(service);
4341  _subReferenceMap.erase(service);
4342  service->removeSubRefComponent();
4343  erase(reference);
4344 }
std::pair< std::string, int > SubjectComponent::getKey ( )
virtual

Definition at line 4272 of file guiObservers.cxx.

References _compoInst, YACS::ENGINE::ComponentInstance::getCompoName(), and YACS::ENGINE::ComponentInstance::getNumId().

4273 {
4274  std::pair<std::string, int> key = std::pair<std::string, int>(_compoInst->getCompoName(), _compoInst->getNumId());
4275  return key;
4276 }
std::map< std::string, std::string > SubjectComponent::getProperties ( )
virtual

Reimplemented from YACS::HMI::Subject.

Definition at line 4392 of file guiObservers.cxx.

References _compoInst, and YACS::ENGINE::PropertyInterface::getProperties().

4393 {
4394  return _compoInst->getProperties();
4395 }
virtual TypeOfElem YACS::HMI::SubjectComponent::getType ( )
inlinevirtual

Reimplemented from YACS::HMI::Subject.

Definition at line 481 of file guiObservers.hxx.

References YACS::HMI::COMPONENT.

Referenced by YACS::HMI::SubjectContainerBase::localclean().

481 {return COMPONENT;}
bool YACS::HMI::SubjectComponent::hasServices ( )
inline

Definition at line 478 of file guiObservers.hxx.

Referenced by moveService(), and YACS::HMI::SubjectServiceNode::~SubjectServiceNode().

478 { return !_subServiceSet.empty(); };
void SubjectComponent::localclean ( Command command = 0)

Definition at line 4230 of file guiObservers.cxx.

References _compoInst, YACS::HMI::GuiContext::_mapOfSubjectContainer, YACS::HMI::GuiContext::_mapOfSubjectNode, DEBTRACE, YACS::HMI::Subject::erase(), YACS::ENGINE::ComponentInstance::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::Subject::getParent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::REMOVE, YACS::HMI::Subject::update(), and YASSERT.

Referenced by clean().

4231 {
4232  DEBTRACE("SubjectComponent::localClean " << this);
4233  Proc* aProc = GuiContext::getCurrent()->getProc();
4234  if ( aProc )
4235  {
4236  std::map<Node*, SubjectNode*>::iterator it = GuiContext::getCurrent()->_mapOfSubjectNode.begin();
4237  std::list<SubjectNode*> services;
4238  for ( ; it!=GuiContext::getCurrent()->_mapOfSubjectNode.end(); it++ )
4239  {
4240  if(ServiceNode* service=dynamic_cast<ServiceNode*>((*it).first))
4241  {
4242  if ( service->getComponent() == _compoInst )
4243  {
4244  services.push_back((*it).second);
4245  }
4246  }
4247  }
4248  while(!services.empty())
4249  {
4250  SubjectNode* son=services.front();
4251  services.pop_front();
4252  Subject* parent=son->getParent();
4253 // parent->update(REMOVE,son->getType(),son);
4254  parent->erase(son);
4255  parent->update(REMOVE,0,0);
4256  }
4257 
4258  Container* container = _compoInst->getContainer();
4259  if (!container) return;
4260  SubjectContainerBase *subContainer(0);
4261  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
4262  subContainer = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
4263  subContainer->removeSubComponentFromSet(this);
4264  }
4265 }
void SubjectComponent::moveService ( SubjectReference reference)
virtual

Definition at line 4346 of file guiObservers.cxx.

References _subReferenceMap, _subServiceSet, YACS::HMI::CUT, DEBTRACE, YACS::HMI::Subject::erase(), YACS::HMI::Subject::getParent(), YACS::HMI::SubjectReference::getReference(), hasServices(), YACS::HMI::PASTE, removeSubServiceFromSet(), YACS::HMI::SubjectReference::reparent(), YACS::HMI::SALOMENODE, YACS::HMI::Subject::update(), and YASSERT.

Referenced by YACS::HMI::SubjectServiceNode::setComponent().

4347 {
4348  DEBTRACE("SubjectComponent::moveService");
4349  SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(reference->getParent());
4350  YASSERT(oldcomp);
4351 
4352  SubjectServiceNode* service = dynamic_cast<SubjectServiceNode*>(reference->getReference());
4353  oldcomp->removeSubServiceFromSet(service);
4354  _subServiceSet.insert(service);
4355  _subReferenceMap[service] = reference;
4356  oldcomp->update(CUT, SALOMENODE, reference);
4357  reference->reparent(this);
4358  update(PASTE, SALOMENODE, reference);
4359  if (!oldcomp->hasServices())
4360  Subject::erase(oldcomp);
4361 }
void SubjectComponent::notifyServicesChange ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Definition at line 4370 of file guiObservers.cxx.

References _subServiceSet, and DEBTRACE.

Referenced by setContainer().

4371 {
4372  DEBTRACE("SubjectComponent::notifyServicesChange");
4373  set<SubjectServiceNode*>::iterator it = _subServiceSet.begin();
4374  for(; it != _subServiceSet.end(); ++it)
4375  {
4376  (*it)->update(event, type, son);
4377  }
4378 }
void SubjectComponent::removeSubServiceFromSet ( SubjectServiceNode service)
virtual

Definition at line 4363 of file guiObservers.cxx.

References _subReferenceMap, _subServiceSet, DEBTRACE, YACS::HMI::SubjectNode::getName(), and getName().

Referenced by YACS::HMI::SubjectServiceNode::localclean(), and moveService().

4364 {
4365  DEBTRACE("SubjectComponent::removeSubServiceFromSet " << getName() << " " << service->getName());
4366  _subServiceSet.erase(service);
4367  _subReferenceMap.erase(service);
4368 }
void SubjectComponent::setContainer ( )
virtual

When loading scheme from file, get the container associated to the component, if any, and create the corresponding subject.

Definition at line 4287 of file guiObservers.cxx.

References _compoInst, YACS::HMI::GuiContext::_mapOfSubjectContainer, _subRefContainer, YACS::HMI::SubjectProc::addSubjectContainer(), YACS::HMI::Subject::addSubjectReference(), YACS::HMI::ASSOCIATE, YACS::HMI::SubjectContainerBase::attachComponent(), YACS::HMI::CONTAINER, DEBTRACE, YACS::ENGINE::ComponentInstance::getContainer(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::Container::getName(), getName(), YACS::HMI::GuiContext::getSubjectProc(), YACS::HMI::SubjectContainerBase::moveComponent(), and notifyServicesChange().

Referenced by YACS::HMI::SubjectContainerBase::localclean().

4288 {
4289  DEBTRACE("SubjectComponent::setContainer " << getName());
4290  Container* container = _compoInst->getContainer();
4291  if (container)
4292  {
4293  SubjectContainerBase *subContainer;
4294  if (GuiContext::getCurrent()->_mapOfSubjectContainer.count(container))
4295  subContainer = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
4296  else
4297  subContainer =
4298  GuiContext::getCurrent()->getSubjectProc()->addSubjectContainer(container, container->getName());
4299  addSubjectReference(subContainer);
4300  if (_subRefContainer)
4301  subContainer->moveComponent(_subRefContainer);
4302  else
4303  _subRefContainer = subContainer->attachComponent(this);
4304  notifyServicesChange(ASSOCIATE, CONTAINER, subContainer);
4305  }
4306 }
bool SubjectComponent::setProperties ( std::map< std::string, std::string >  properties)
virtual

Reimplemented from YACS::HMI::Subject.

Definition at line 4380 of file guiObservers.cxx.

References YACS::HMI::Invocator::add(), YACS::HMI::Command::execute(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getInvoc(), and getName().

4381 {
4383  if (command->execute())
4384  {
4385  GuiContext::getCurrent()->getInvoc()->add(command);
4386  return true;
4387  }
4388  else delete command;
4389  return false;
4390 }

Friends And Related Function Documentation

friend class SubjectNode
friend

Definition at line 463 of file guiObservers.hxx.

Member Data Documentation

int YACS::HMI::SubjectComponent::_id
protected

Definition at line 484 of file guiObservers.hxx.

SubjectReference* YACS::HMI::SubjectComponent::_subRefContainer

Definition at line 482 of file guiObservers.hxx.

Referenced by setContainer(), and SubjectComponent().

std::map<SubjectServiceNode*,SubjectReference*> YACS::HMI::SubjectComponent::_subReferenceMap
protected
std::set<SubjectServiceNode*> YACS::HMI::SubjectComponent::_subServiceSet
protected

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