Version: 8.3.0
YACS::HMI::CommandAddNodeFromCatalog Class Reference

#include <commandsProc.hxx>

Inheritance diagram for YACS::HMI::CommandAddNodeFromCatalog:
Collaboration diagram for YACS::HMI::CommandAddNodeFromCatalog:

Public Member Functions

 CommandAddNodeFromCatalog (YACS::ENGINE::Catalog *catalog, std::string compo, std::string type, std::string position, std::string name, bool newCompoInst=true, int swCase=0)
 
YACS::ENGINE::NodegetNode ()
 
YACS::HMI::SubjectNodegetSubjectNode ()
 
- 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
 
TypeOfElem _typeNode
 
std::string _compoName
 
std::string _typeName
 
std::string _position
 
std::string _name
 
bool _newCompoInst
 
int _swCase
 
YACS::ENGINE::Node_node
 
YACS::HMI::SubjectNode_snode
 
- Protected Attributes inherited from YACS::HMI::Command
std::vector< Command * > _subCommands
 
bool _normalReverse
 

Detailed Description

Definition at line 108 of file commandsProc.hxx.

Constructor & Destructor Documentation

CommandAddNodeFromCatalog::CommandAddNodeFromCatalog ( YACS::ENGINE::Catalog catalog,
std::string  compo,
std::string  type,
std::string  position,
std::string  name,
bool  newCompoInst = true,
int  swCase = 0 
)

Definition at line 180 of file commandsProc.cxx.

References _node, _snode, and DEBTRACE.

187  : Command(), _catalog(catalog), _compoName(compo), _typeName(type),
188  _position(position), _name(name), _newCompoInst(newCompoInst), _swCase(swCase)
189 {
190  DEBTRACE("CommandAddNodeFromCatalog " << compo << " " << type << " " << position << " " << name);
191  _node=0;
192  _snode=0;
193 }

Member Function Documentation

std::string CommandAddNodeFromCatalog::dump ( )
protectedvirtual

Reimplemented from YACS::HMI::Command.

Definition at line 195 of file commandsProc.cxx.

References _compoName, _name, _position, _typeName, and PMMLBasicsTestLauncher::ret.

196 {
197  string ret ="CommandAddNodeFromCatalog " + _compoName + " " + _typeName + " " + _position + " " + _name;
198  return ret;
199 }
YACS::ENGINE::Node * CommandAddNodeFromCatalog::getNode ( )

Definition at line 201 of file commandsProc.cxx.

References _node.

Referenced by YACS::HMI::SubjectComposedNode::createNode().

202 {
203  return _node;
204 }
YACS::HMI::SubjectNode * CommandAddNodeFromCatalog::getSubjectNode ( )

Definition at line 206 of file commandsProc.cxx.

References _snode.

Referenced by YACS::HMI::SubjectComposedNode::createNode().

207 {
208  return _snode;
209 }
bool CommandAddNodeFromCatalog::localExecute ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 211 of file commandsProc.cxx.

References _catalog, _compoName, YACS::ENGINE::Catalog::_componentMap, YACS::ENGINE::Catalog::_composednodeMap, YACS::HMI::GuiContext::_mapOfLastComponentInstance, YACS::HMI::GuiContext::_mapOfSubjectNode, _name, _newCompoInst, _node, YACS::ENGINE::Catalog::_nodeMap, _position, YACS::ENGINE::ComponentDefinition::_serviceMap, _snode, _swCase, _typeName, _typeNode, YACS::HMI::SubjectComposedNode::addSubjectNode(), YACS::HMI::BLOC, YACS::ENGINE::Node::clone(), DEBTRACE, YACS::HMI::FOREACHLOOP, YACS::HMI::FORLOOP, YACS::ENGINE::ComposedNode::getChildByName(), YACS::ENGINE::ComponentInstance::getCompoName(), YACS::ENGINE::ServiceNode::getComponent(), YACS::HMI::GuiContext::getCurrent(), YACS::ENGINE::ComponentInstance::getInstanceName(), YACS::HMI::GuiContext::getProc(), YACS::HMI::ProcInvoc::getTypeOfNode(), YACS::HMI::Subject::loadChildren(), YACS::HMI::Subject::loadLinks(), YACS::HMI::OPTIMIZERLOOP, YACS::ENGINE::ServiceNode::setComponent(), YACS::HMI::GuiContext::setCurrentCatalog(), setErrorMsg(), YACS::ENGINE::Node::setName(), YACS::HMI::SWITCH, YACS::Exception::what(), YACS::HMI::WHILELOOP, and YASSERT.

212 {
213  DEBTRACE("CommandAddNodeFromCatalog::localExecute");
214 
215  Node *son = 0;
216  Node *nodeToClone = 0;
217  try
218  {
219  if (_compoName.empty())
220  {
221  if (_catalog->_nodeMap.count(_typeName))
222  nodeToClone = _catalog->_nodeMap[_typeName];
223  else if (_catalog->_composednodeMap.count(_typeName))
224  nodeToClone = _catalog->_composednodeMap[_typeName];
225  }
226  else
227  if (_catalog->_componentMap.count(_compoName))
228  {
230  if (compodef->_serviceMap.count(_typeName))
231  nodeToClone = compodef->_serviceMap[_typeName];
232  }
233  if (nodeToClone)
234  _typeNode = ProcInvoc::getTypeOfNode(nodeToClone);
235 
237  Proc* proc = GuiContext::getCurrent()->getProc();
238  Node* node = proc;
239  ServiceNode *service = 0;
240 
241  if (!_position.empty()) node = proc->getChildByName(_position);
242  ComposedNode* father =dynamic_cast<ComposedNode*> (node);
243  if (father && nodeToClone)
244  {
245  son = nodeToClone->clone(0);
246  son->setName(_name);
247  service = dynamic_cast<ServiceNode*>(son);
248  }
249 
250  // Node creation eventually reusing old component instance
251  ComponentInstance *compo = 0;
252  if (service)
253  compo = service->getComponent();
254 
255  if(compo)
256  {
257  std::string compoName=compo->getCompoName();
258  DEBTRACE(compoName);
259  std::string compoInstName=compo->getInstanceName();
260  DEBTRACE(compoInstName);
261  if(!_newCompoInst)
262  {
264  DEBTRACE(lastcompo);
265  if(lastcompo)
266  {
267  DEBTRACE(lastcompo->getInstanceName());
268  service->setComponent(lastcompo); // use the last component instance of the same type and not a new instance
269  }
270  else
272  }
273  else
275  }
276 
277  if (son)
278  {
279  TypeOfElem fatherType = ProcInvoc::getTypeOfNode(father);
280  switch (fatherType)
281  {
282  case BLOC:
283  (dynamic_cast<YACS::ENGINE::Bloc*>(father))->edAddChild(son);
284  break;
285  case FORLOOP:
286  (dynamic_cast<YACS::ENGINE::ForLoop*>(father))->edSetNode(son);
287  break;
288  case WHILELOOP:
289  (dynamic_cast<YACS::ENGINE::WhileLoop*>(father))->edSetNode(son);
290  break;
291  case SWITCH:
292  (dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
293  break;
294  case FOREACHLOOP:
295  (dynamic_cast<YACS::ENGINE::ForEachLoop*>(father))->edSetNode(son);
296  break;
297  case OPTIMIZERLOOP:
298  (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
299  break;
300  default:
301  YASSERT(0);
302  }
303  }
304  _node = son;
305  if (!_node)
306  throw YACS::Exception("node from catalog is not correct: check if catalog is up to date!");
307 
310  _snode->loadChildren();
311  _snode->loadLinks();
312  }
313  catch (Exception& ex)
314  {
315  DEBTRACE("CommandAddNode::localExecute() : " << ex.what());
316  setErrorMsg(ex);
317  if (son) delete son;
318  _node = 0;
319  }
320  return (_node != 0);
321 }
bool CommandAddNodeFromCatalog::localReverse ( )
protectedvirtual

Implements YACS::HMI::Command.

Definition at line 323 of file commandsProc.cxx.

References YACS::HMI::GuiContext::_mapOfSubjectNode, _name, _node, _position, _snode, DEBTRACE, YACS::HMI::Subject::erase(), YACS::ENGINE::ComposedNode::getChildByName(), YACS::HMI::GuiContext::getCurrent(), YACS::HMI::Subject::getName(), YACS::HMI::Subject::getParent(), YACS::HMI::GuiContext::getProc(), YACS::HMI::REMOVE, YACS::HMI::Subject::select(), setErrorMsg(), YACS::HMI::Subject::update(), YACS::Exception::what(), and YASSERT.

324 {
325  DEBTRACE("CommandAddNodeFromCatalog::localReverse");
326  try
327  {
328  Proc* proc = GuiContext::getCurrent()->getProc();
329  string nodeName;
330  if (_position.empty())
331  nodeName= _name;
332  else
333  nodeName = _position + "." + _name;
334  DEBTRACE(nodeName);
335  _node = proc->getChildByName(nodeName);
336  YASSERT(_node);
337  YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_node));
339 
340  Subject *father=_snode->getParent();
341  DEBTRACE(father);
342  DEBTRACE(father->getName());
343  Subject::erase(_snode);
344  _snode= 0;
345  _node = 0;
346  if (father)
347  {
348  DEBTRACE("REMOVE");
349  father->select(true);
350  father->update(REMOVE,0,0);
351  }
352  return true;
353  }
354  catch (Exception& ex)
355  {
356  DEBTRACE("CommandAddNodeFromCatalog::localReverse(): " << ex.what());
357  setErrorMsg(ex);
358  return false;
359  }
360 }

Member Data Documentation

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

Definition at line 124 of file commandsProc.hxx.

Referenced by localExecute().

std::string YACS::HMI::CommandAddNodeFromCatalog::_compoName
protected

Definition at line 126 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

std::string YACS::HMI::CommandAddNodeFromCatalog::_name
protected

Definition at line 129 of file commandsProc.hxx.

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

bool YACS::HMI::CommandAddNodeFromCatalog::_newCompoInst
protected

Definition at line 130 of file commandsProc.hxx.

Referenced by localExecute().

YACS::ENGINE::Node* YACS::HMI::CommandAddNodeFromCatalog::_node
protected

Definition at line 132 of file commandsProc.hxx.

Referenced by CommandAddNodeFromCatalog(), getNode(), localExecute(), and localReverse().

std::string YACS::HMI::CommandAddNodeFromCatalog::_position
protected

Definition at line 128 of file commandsProc.hxx.

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

YACS::HMI::SubjectNode* YACS::HMI::CommandAddNodeFromCatalog::_snode
protected
int YACS::HMI::CommandAddNodeFromCatalog::_swCase
protected

Definition at line 131 of file commandsProc.hxx.

Referenced by localExecute().

std::string YACS::HMI::CommandAddNodeFromCatalog::_typeName
protected

Definition at line 127 of file commandsProc.hxx.

Referenced by dump(), and localExecute().

TypeOfElem YACS::HMI::CommandAddNodeFromCatalog::_typeNode
protected

Definition at line 125 of file commandsProc.hxx.

Referenced by localExecute().


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