Version: 8.3.0
YACS::HMI::Subject Class Reference

#include <guiObservers.hxx>

Inheritance diagram for YACS::HMI::Subject:
Collaboration diagram for YACS::HMI::Subject:

Public Member Functions

 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 std::string getName ()
 
virtual bool setName (std::string name)
 
virtual bool setProperties (std::map< std::string, std::string > properties)
 
virtual std::map< std::string,
std::string > 
getProperties ()
 
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)
 
virtual void clean (Command *command=0)
 
void localclean (Command *command=0)
 
void registerUndoDestroy ()
 
void askRegisterUndoDestroy ()
 
bool isDestructible ()
 
virtual TypeOfElem getType ()
 
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 ()
 

Static Public Member Functions

static void erase (Subject *sub, Command *command=0, bool post=false)
 

Protected Attributes

std::set< GuiObserver * > _setObs
 
Subject_parent
 
bool _destructible
 
bool _askRegisterUndo
 
std::string _progress
 

Friends

class CommandReparentNode
 

Detailed Description

Definition at line 116 of file guiObservers.hxx.

Constructor & Destructor Documentation

Subject::Subject ( Subject parent = 0)

Definition at line 85 of file guiObservers.cxx.

References _askRegisterUndo, and _destructible.

85  : _parent(parent)
86 {
87  _destructible = true;
88  _askRegisterUndo = false;
89 }
Subject::~Subject ( )
virtual

Destructor must only be called by Subject::erase to clean completely the context (detach observers), before the delete process itself. Some actions involving dynamic_cast can't be done in destructor.

Definition at line 97 of file guiObservers.cxx.

References DEBTRACE, and getName().

98 {
99  DEBTRACE("Subject::~Subject " << this << " "<< getName());
100 }

Member Function Documentation

void Subject::addSubjectReference ( Subject ref)
virtual

Reimplemented in YACS::HMI::SubjectServiceNode.

Definition at line 322 of file guiObservers.cxx.

References YACS::HMI::ADDREF, DEBTRACE, getName(), and update().

Referenced by YACS::HMI::SubjectComponent::setContainer().

323 {
324  DEBTRACE("Subject::addSubjectReference " << getName() << " " << ref->getName());
325  SubjectReference *son = new SubjectReference(ref, this);
326  update(ADDREF, 0, son);
327 }
void YACS::HMI::Subject::askRegisterUndoDestroy ( )
inline

Definition at line 140 of file guiObservers.hxx.

Referenced by YACS::HMI::GuiEditor::DeleteSubject().

140 {_askRegisterUndo=true; };
void Subject::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 in YACS::HMI::SubjectControlLink, YACS::HMI::SubjectLink, YACS::HMI::SubjectStudyOutNode, YACS::HMI::SubjectStudyInNode, YACS::HMI::SubjectOutNode, YACS::HMI::SubjectPresetNode, YACS::HMI::SubjectDataNode, YACS::HMI::SubjectSplitterNode, YACS::HMI::SubjectXmlNode, YACS::HMI::SubjectSalomePythonNode, YACS::HMI::SubjectSalomeNode, YACS::HMI::SubjectCppNode, YACS::HMI::SubjectCORBANode, YACS::HMI::SubjectServiceNode, YACS::HMI::SubjectPyFuncNode, YACS::HMI::SubjectPythonNode, YACS::HMI::SubjectInlineNode, YACS::HMI::SubjectElementaryNode, YACS::HMI::SubjectOptimizerLoop, YACS::HMI::SubjectForEachLoop, YACS::HMI::SubjectDynParaLoop, YACS::HMI::SubjectSwitch, YACS::HMI::SubjectWhileLoop, YACS::HMI::SubjectForLoop, YACS::HMI::SubjectProc, YACS::HMI::SubjectDataType, YACS::HMI::SubjectComponent, YACS::HMI::SubjectContainerBase, YACS::HMI::SubjectBloc, YACS::HMI::SubjectComposedNode, YACS::HMI::SubjectNode, YACS::HMI::SubjectOutputDataStreamPort, YACS::HMI::SubjectInputDataStreamPort, YACS::HMI::SubjectOutputPort, YACS::HMI::SubjectInputPort, YACS::HMI::SubjectDataPort, and YACS::HMI::SubjectReference.

Definition at line 107 of file guiObservers.cxx.

References localclean().

Referenced by YACS::HMI::SubjectReference::clean(), YACS::HMI::SubjectDataPort::clean(), YACS::HMI::SubjectNode::clean(), YACS::HMI::SubjectContainerBase::clean(), YACS::HMI::SubjectComponent::clean(), YACS::HMI::SubjectDataType::clean(), YACS::HMI::SubjectLink::clean(), YACS::HMI::SubjectControlLink::clean(), and erase().

108 {
109  localclean(command);
110 }
bool Subject::destroy ( Subject son)
virtual

From user action in Ihm, destroy an object.

Called from GuiEditor::DeleteSubject(parent, toRemove). The subject (this) is the parent of the subject (son) to remove. Son must represent a Node, a DataPort, a Link or a ControlLink. All other objects can only be destroyed automatically, not via an user command. Only the destruction originated from user, using this method, are registered for undo-redo.

Definition at line 238 of file guiObservers.cxx.

References YACS::HMI::GuiContext::_lastErrorMessage, YACS::HMI::Invocator::add(), DEBTRACE, YACS::HMI::Command::execute(), YACS::ENGINE::ComposedNode::getChildName(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::GuiContext::getInvoc(), YACS::ENGINE::ComposedNode::getName(), getName(), YACS::HMI::SubjectNode::getNode(), getParent(), YACS::HMI::GuiContext::getProc(), getType(), isDestructible(), and YACS::HMI::UNKNOWN.

Referenced by YACS::HMI::GuiEditor::DeleteSubject(), and YACS::HMI::SubjectContainerBase::~SubjectContainerBase().

239 {
240  string toDestroy = son->getName();
241  DEBTRACE("Subject::destroy " << toDestroy);
242  Proc *proc = GuiContext::getCurrent()->getProc();
243  string startnode = "";
244  string endnode = "";
245  string startport = "";
246  string endport = "";
247  TypeOfElem startportType = UNKNOWN;
248  TypeOfElem endportType = UNKNOWN;
249 
250  if (dynamic_cast<SubjectProc*>(son))
251  startnode = proc->getName();
252  else
253  {
254  if (SubjectNode *subNode = dynamic_cast<SubjectNode*>(son))
255  {
256  if (subNode->getNode()->getFather() )
257  startnode = proc->getChildName(subNode->getNode());
258  }
259  else if (dynamic_cast<SubjectDataPort*>(son))
260  {
261  SubjectNode *subNodep = dynamic_cast<SubjectNode*>(son->getParent());
262  startnode = proc->getChildName(subNodep->getNode());
263  startport = son->getName();
264  startportType = son->getType();
265  }
266  else if (SubjectLink* slink = dynamic_cast<SubjectLink*>(son))
267  {
268  startnode = proc->getChildName(slink->getSubjectOutNode()->getNode());
269  endnode = proc->getChildName(slink->getSubjectInNode()->getNode());
270  startport = slink->getSubjectOutPort()->getName();
271  endport = slink->getSubjectInPort()->getName();
272  startportType = slink->getSubjectOutPort()->getType();
273  endportType = slink->getSubjectInPort()->getType();
274  }
275  else if (SubjectControlLink* sclink = dynamic_cast<SubjectControlLink*>(son))
276  {
277  startnode = proc->getChildName(sclink->getSubjectOutNode()->getNode());
278  endnode = proc->getChildName(sclink->getSubjectInNode()->getNode());
279  }
280  else if (SubjectContainerBase* scont = dynamic_cast<SubjectContainerBase*>(son))
281  {
282  if(scont->getName() == "DefaultContainer")
283  {
284  GuiContext::getCurrent()->_lastErrorMessage = "You can't delete the default container";
285  return false;
286  }
287  if(scont->isUsed())
288  {
289  GuiContext::getCurrent()->_lastErrorMessage = "You can't delete a container that contains components";
290  return false;
291  }
292  startnode = scont->getName();
293  }
294  else
295  {
296  GuiContext::getCurrent()->_lastErrorMessage = "No command Destroy for that type";
297  return false;
298  }
299  }
300  if (son->isDestructible())
301  {
302  CommandDestroy* command = new CommandDestroy(son->getType(), startnode, startport, startportType, endnode, endport, endportType);
303  if (command->execute())
304  {
305  DEBTRACE("Destruction done: " << toDestroy);
306  GuiContext::getCurrent()->getInvoc()->add(command);
307  return true;
308  }
309  else delete command;
310  }
311  return false;
312 }
void Subject::detach ( GuiObserver obs)
virtual

Definition at line 153 of file guiObservers.cxx.

References _setObs, DEBTRACE, and YACS::HMI::GuiObserver::decrementSubjects().

Referenced by localclean().

154 {
155  DEBTRACE("Subject::detach " << obs);
156  obs->decrementSubjects(this);
157  _setObs.erase(obs);
158 }
void Subject::erase ( Subject sub,
Command command = 0,
bool  post = false 
)
static

Definition at line 74 of file guiObservers.cxx.

References clean(), and getParent().

Referenced by YACS::HMI::SubjectProc::cleanPostErase(), YACS::HMI::GenericGui::closeContext(), YACS::HMI::SubjectContainerBase::detachComponent(), YACS::HMI::SubjectComponent::detachService(), YACS::HMI::SubjectDataPort::localclean(), YACS::HMI::SubjectNode::localclean(), YACS::HMI::SubjectBloc::localclean(), YACS::HMI::SubjectContainerBase::localclean(), YACS::HMI::SubjectComponent::localclean(), YACS::HMI::SubjectForLoop::localclean(), YACS::HMI::SubjectWhileLoop::localclean(), YACS::HMI::SubjectSwitch::localclean(), YACS::HMI::SubjectDynParaLoop::localclean(), YACS::HMI::SubjectForEachLoop::localclean(), YACS::HMI::SubjectServiceNode::localclean(), YACS::HMI::CommandDestroy::localExecute(), YACS::HMI::CommandAddNodeFromCatalog::localReverse(), YACS::HMI::CommandPutInComposedNode::localReverse(), YACS::HMI::CommandCopyNode::localReverse(), YACS::HMI::CommandAddInputPortFromCatalog::localReverse(), YACS::HMI::CommandAddOutputPortFromCatalog::localReverse(), YACS::HMI::CommandAddIDSPortFromCatalog::localReverse(), YACS::HMI::CommandAddODSPortFromCatalog::localReverse(), YACS::HMI::CommandAddLink::localReverse(), YACS::HMI::CommandAddControlLink::localReverse(), YACS::HMI::SubjectComponent::moveService(), YACS::HMI::SubjectNode::removeExternalControlLinks(), YACS::HMI::SubjectComposedNode::removeExternalControlLinks(), YACS::HMI::SubjectNode::removeExternalLinks(), YACS::HMI::SubjectProc::removeSubjectContainer(), YACS::HMI::SubjectProc::removeSubjectDataType(), and YACS::HMI::GuiContext::setProc().

75 {
76  Subject* parent =sub->getParent();
77  sub->clean(command);
78  delete sub;
79  if (!post) // --- avoid recursion in erase, see cleanPostErase
81 }
std::string Subject::getName ( )
virtual

Reimplemented in YACS::HMI::SubjectControlLink, YACS::HMI::SubjectLink, YACS::HMI::SubjectSplitterNode, YACS::HMI::SubjectDataType, YACS::HMI::SubjectComponent, YACS::HMI::SubjectContainerBase, YACS::HMI::SubjectNode, YACS::HMI::SubjectDataPort, and YACS::HMI::SubjectReference.

Definition at line 160 of file guiObservers.cxx.

Referenced by YACS::HMI::SchemaContainerItem::addComponentInstance(), YACS::HMI::SchemaDirContainersItem::addContainerItem(), YACS::HMI::SchemaDirLinksItem::addLinkItem(), addSubjectReference(), YACS::HMI::SubjectServiceNode::addSubjectReference(), YACS::HMI::GuiEditor::arrangeNodes(), YACS::HMI::GuiEditor::CopySubject(), YACS::HMI::GenericGui::createContext(), YACS::HMI::ValueDelegate::createEditor(), YACS::HMI::GuiEditor::CreateNode(), YACS::HMI::GuiEditor::CutSubject(), YACS::HMI::GuiEditor::DeleteSubject(), destroy(), YACS::HMI::GenericGui::displayPortLinks(), YACS::HMI::SchemaModel::dropMimeData(), YACS::HMI::SceneNodeItem::getHeaderLabel(), YACS::HMI::SubjectReference::getName(), YACS::HMI::ItemEditionBase::ItemEditionBase(), YACS::HMI::SubjectLink::localclean(), YACS::HMI::SubjectControlLink::localclean(), YACS::HMI::CommandAddNodeFromCatalog::localReverse(), YACS::HMI::TablePortsEdition::on_pb_insert_clicked(), YACS::HMI::TablePortsEdition::on_pb_remove_clicked(), YACS::HMI::TablePortsEdition::oncb_insert_activated(), YACS::HMI::GenericGui::onEmphasisCtrlLinks(), YACS::HMI::GenericGui::onEmphasisPortLinks(), YACS::HMI::SchemaContainerItem::SchemaContainerItem(), YACS::HMI::RootSceneItem::setNewRoot(), YACS::HMI::SchemaModel::setNewRoot(), YACS::HMI::ValueDelegate::setResultEditing(), YACS::HMI::SchemaContainerItem::update(), YACS::HMI::SchemaComponentItem::update(), YACS::HMI::SchemaReferenceItem::update(), YACS::HMI::SchemaNodeItem::update(), YACS::HMI::SchemaComposedNodeItem::update(), YACS::HMI::SceneComposedNodeItem::update(), YACS::HMI::SceneElementaryNodeItem::update(), YACS::HMI::EditionContainer::update(), YACS::HMI::SceneDataPortItem::update(), YACS::HMI::EditionSalomeNode::update(), YACS::HMI::SceneNodeItem::update(), YACS::HMI::ItemEdition::update(), YACS::HMI::SchemaModel::updateSelection(), YACS::HMI::TablePortsEdition::upOrDown(), and ~Subject().

161 {
162  return "generic";
163 }
Subject * Subject::getParent ( )
virtual
virtual std::string YACS::HMI::Subject::getProgress ( )
inlinevirtual

Definition at line 145 of file guiObservers.hxx.

Referenced by YACS::HMI::SceneComposedNodeItem::update().

145 { return _progress; };
std::map< std::string, std::string > Subject::getProperties ( )
virtual
bool YACS::HMI::Subject::isDestructible ( )
inline
std::vector< std::string > Subject::knownProperties ( )
virtual

Reimplemented in YACS::HMI::SubjectLink, and YACS::HMI::SubjectInputDataStreamPort.

Definition at line 181 of file guiObservers.cxx.

Referenced by YACS::HMI::SubjectLink::knownProperties(), and YACS::HMI::PropertyEditor::PropertyEditor().

182 {
183  std::vector<std::string> empty;
184  return empty;
185 }
void Subject::loadLinks ( )
virtual
void Subject::localclean ( Command command = 0)

the local clean method of base class of subjects take care of Observers. Remaining Observers in the list are detached, if an observer has no more Subject to observe, it can be deleted.

Definition at line 117 of file guiObservers.cxx.

References _setObs, DEBTRACE, detach(), YACS::HMI::GuiObserver::getNbSubjects(), and isDestructible().

Referenced by clean().

118 {
119  DEBTRACE("Subject::localClean ");
120  set<GuiObserver*>::iterator it;
121  while (int nbObs = _setObs.size())
122  {
123  DEBTRACE("--- " << this << " nbObs " << nbObs);
124  set<GuiObserver*> copySet = _setObs;
125  for (it = copySet.begin(); it != copySet.end(); ++it)
126  {
127  GuiObserver* anObs = (*it);
128  detach(anObs);
129  int nbsub = anObs->getNbSubjects();
130  DEBTRACE("nbSubjects=" << nbsub << " obs=" << anObs);
131  if (nbsub <= 0 && anObs->isDestructible())
132  {
133  delete anObs ;
134  break; // --- each delete may induce remove of other observers
135  }
136  }
137  }
138  _setObs.clear();
139 }
void Subject::registerUndoDestroy ( )

Definition at line 141 of file guiObservers.cxx.

References DEBTRACE.

Referenced by YACS::HMI::SubjectReference::clean(), YACS::HMI::SubjectContainerBase::clean(), YACS::HMI::SubjectComponent::clean(), and YACS::HMI::SubjectDataType::clean().

142 {
143  DEBTRACE("Subject::registerUndoDestroy");
144 }
bool Subject::setName ( std::string  name)
virtual

Reimplemented in YACS::HMI::SubjectContainerBase, YACS::HMI::SubjectNode, and YACS::HMI::SubjectDataPort.

Definition at line 165 of file guiObservers.cxx.

Referenced by YACS::HMI::ItemEdition::onApply().

166 {
167  return false;
168 }
void Subject::setParent ( Subject son)
virtual

Definition at line 225 of file guiObservers.cxx.

References _parent.

Referenced by YACS::HMI::CommandPutInComposedNode::localExecute(), and YACS::HMI::CommandPutInComposedNode::localReverse().

226 {
227  _parent=son;
228 }
void Subject::setProgress ( std::string  newProgress)
virtual

Definition at line 329 of file guiObservers.cxx.

References _progress.

330 {
331  _progress = newProgress;
332 }
bool Subject::setProperties ( std::map< std::string, std::string >  properties)
virtual
void Subject::update ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Reimplemented in YACS::HMI::SubjectNode.

Definition at line 198 of file guiObservers.cxx.

References _setObs, and YACS::Exception::what().

Referenced by YACS::HMI::SubjectComposedNode::addSubjectLink(), addSubjectReference(), YACS::HMI::SubjectContainerBase::attachComponent(), YACS::HMI::SubjectComponent::attachService(), gui.graph.MyCanvas::customEvent(), YACS::HMI::SubjectContainerBase::detachComponent(), YACS::HMI::SubjectComponent::detachService(), YACS::HMI::GenericGui::emphasizePortLink(), YACS::HMI::SubjectComponent::localclean(), YACS::HMI::CommandAddInputPortFromCatalog::localExecute(), YACS::HMI::CommandAddOutputPortFromCatalog::localExecute(), YACS::HMI::CommandSetInPortValue::localExecute(), YACS::HMI::CommandSetOutPortValue::localExecute(), YACS::HMI::CommandSetContainerProperties::localExecute(), YACS::HMI::CommandSetComponentInstanceProperties::localExecute(), YACS::HMI::CommandDestroy::localExecute(), YACS::HMI::CommandAddNodeFromCatalog::localReverse(), YACS::HMI::CommandCopyNode::localReverse(), YACS::HMI::CommandAddInputPortFromCatalog::localReverse(), YACS::HMI::CommandAddOutputPortFromCatalog::localReverse(), YACS::HMI::CommandAddIDSPortFromCatalog::localReverse(), YACS::HMI::CommandAddODSPortFromCatalog::localReverse(), YACS::HMI::CommandSetInPortValue::localReverse(), YACS::HMI::CommandSetOutPortValue::localReverse(), YACS::HMI::CommandAddLink::localReverse(), YACS::HMI::CommandAddControlLink::localReverse(), YACS::HMI::CommandSetComponentInstanceProperties::localReverse(), YACS::HMI::SubjectContainerBase::moveComponent(), YACS::HMI::SubjectComponent::moveService(), YACS::HMI::GenericGui::onDeEmphasizeAll(), YACS::HMI::GenericGui::onEmphasisCtrlLinks(), YACS::HMI::GenericGui::onEmphasisLink(), YACS::HMI::GenericGui::onToggleStraightLinks(), YACS::HMI::ItemEdition::setEdited(), YACS::HMI::GuiContext::setProc(), YACS::HMI::ValueDelegate::setResultEditing(), YACS::HMI::EditionWhile::synchronize(), YACS::HMI::EditionLoop::synchronize(), YACS::HMI::EditionForEachLoop::synchronize(), YACS::HMI::EditionOptimizerLoop::synchronize(), YACS::HMI::EditionSwitch::synchronize(), YACS::HMI::SubjectObserver::update(), YACS::HMI::SubjectNode::update(), and YACS::HMI::SubjectLink::~SubjectLink().

199 {
200  //DEBTRACE("Subject::update " << type << "," << GuiObserver::eventName(event) << "," << son);
201  set<GuiObserver*> copySet = _setObs;
202  for (set<GuiObserver *>::iterator it = copySet.begin(); it != copySet.end(); ++it)
203  {
204  //DEBTRACE("Subject::update " << *it);
205  try
206  {
207  (*it)->update(event, type, son);
208  }
209  catch(Exception& ex)
210  {
211  std::cerr << "Internal error in Subject::update: " << ex.what() << std::endl;
212  }
213  catch(...)
214  {
215  std::cerr << "Internal error in Subject::update: " << std::endl;
216  }
217  }
218 }

Friends And Related Function Documentation

friend class CommandReparentNode
friend

Definition at line 119 of file guiObservers.hxx.

Referenced by YACS::HMI::SubjectNode::reparent().

Member Data Documentation

bool YACS::HMI::Subject::_askRegisterUndo
protected

Definition at line 150 of file guiObservers.hxx.

Referenced by YACS::HMI::SubjectReference::clean(), YACS::HMI::SubjectDataPort::clean(), YACS::HMI::SubjectInputPort::clean(), YACS::HMI::SubjectOutputPort::clean(), YACS::HMI::SubjectInputDataStreamPort::clean(), YACS::HMI::SubjectOutputDataStreamPort::clean(), YACS::HMI::SubjectNode::clean(), YACS::HMI::SubjectComposedNode::clean(), YACS::HMI::SubjectBloc::clean(), YACS::HMI::SubjectContainerBase::clean(), YACS::HMI::SubjectComponent::clean(), YACS::HMI::SubjectDataType::clean(), YACS::HMI::SubjectProc::clean(), YACS::HMI::SubjectForLoop::clean(), YACS::HMI::SubjectWhileLoop::clean(), YACS::HMI::SubjectSwitch::clean(), YACS::HMI::SubjectDynParaLoop::clean(), YACS::HMI::SubjectForEachLoop::clean(), YACS::HMI::SubjectOptimizerLoop::clean(), YACS::HMI::SubjectElementaryNode::clean(), YACS::HMI::SubjectInlineNode::clean(), YACS::HMI::SubjectPythonNode::clean(), YACS::HMI::SubjectPyFuncNode::clean(), YACS::HMI::SubjectServiceNode::clean(), YACS::HMI::SubjectCORBANode::clean(), YACS::HMI::SubjectCppNode::clean(), YACS::HMI::SubjectSalomeNode::clean(), YACS::HMI::SubjectSalomePythonNode::clean(), YACS::HMI::SubjectXmlNode::clean(), YACS::HMI::SubjectSplitterNode::clean(), YACS::HMI::SubjectDataNode::clean(), YACS::HMI::SubjectPresetNode::clean(), YACS::HMI::SubjectOutNode::clean(), YACS::HMI::SubjectStudyInNode::clean(), YACS::HMI::SubjectStudyOutNode::clean(), YACS::HMI::SubjectLink::clean(), YACS::HMI::SubjectControlLink::clean(), and Subject().

std::string YACS::HMI::Subject::_progress
protected

Definition at line 151 of file guiObservers.hxx.

Referenced by setProgress().

std::set<GuiObserver *> YACS::HMI::Subject::_setObs
protected

Definition at line 145 of file guiObservers.hxx.

Referenced by attach(), detach(), localclean(), select(), and update().


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