Version: 8.3.0
guiObservers.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 #include <Python.h>
21 #include "guiObservers.hxx"
22 #include "commandsProc.hxx"
23 #include "Node.hxx"
24 #include "ComposedNode.hxx"
25 #include "Bloc.hxx"
26 #include "Proc.hxx"
27 #include "ElementaryNode.hxx"
28 #include "InlineNode.hxx"
29 #include "ServiceNode.hxx"
30 #include "PythonNode.hxx"
31 #include "CORBANode.hxx"
32 #include "CppNode.hxx"
33 #include "XMLNode.hxx"
34 #include "SalomePythonNode.hxx"
35 #include "DataNode.hxx"
36 #include "PresetNode.hxx"
37 #include "OutNode.hxx"
38 #include "StudyNodes.hxx"
39 #include "ForLoop.hxx"
40 #include "ForEachLoop.hxx"
41 #include "WhileLoop.hxx"
42 #include "Switch.hxx"
43 #include "OptimizerLoop.hxx"
44 #include "InputPort.hxx"
45 #include "OutputPort.hxx"
46 #include "InputDataStreamPort.hxx"
47 #include "OutputDataStreamPort.hxx"
48 #include "SalomeHPContainer.hxx"
49 #include "SalomeContainer.hxx"
50 #include "SalomeComponent.hxx"
51 #include "ComponentDefinition.hxx"
52 #include "TypeCode.hxx"
53 #include "RuntimeSALOME.hxx"
54 
55 #include "guiContext.hxx"
56 
57 #include <string>
58 #include <sstream>
59 #include <vector>
60 
61 //#define _DEVDEBUG_
62 #include "YacsTrace.hxx"
63 
64 using namespace std;
65 
66 using namespace YACS;
67 using namespace YACS::HMI;
68 using namespace YACS::ENGINE;
69 
70 std::map<int, std::string> GuiObserver::_eventNameMap;
71 
72 // ----------------------------------------------------------------------------
73 
74 void Subject::erase(Subject* sub, Command *command, bool post)
75 {
76  Subject* parent =sub->getParent();
77  sub->clean(command);
78  delete sub;
79  if (!post) // --- avoid recursion in erase, see cleanPostErase
80  GuiContext::getCurrent()->getSubjectProc()->cleanPostErase();
81 }
82 
83 // ----------------------------------------------------------------------------
84 
85 Subject::Subject(Subject *parent) : _parent(parent)
86 {
87  _destructible = true;
88  _askRegisterUndo = false;
89 }
90 
98 {
99  DEBTRACE("Subject::~Subject " << this << " "<< getName());
100 }
101 
107 void Subject::clean(Command *command)
108 {
109  localclean(command);
110 }
111 
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 }
140 
142 {
143  DEBTRACE("Subject::registerUndoDestroy");
144 }
145 
147 {
148  DEBTRACE("Subject::attach " << obs);
149  _setObs.insert(obs);
150  obs->incrementSubjects(this);
151 }
152 
154 {
155  DEBTRACE("Subject::detach " << obs);
156  obs->decrementSubjects(this);
157  _setObs.erase(obs);
158 }
159 
160 std::string Subject::getName()
161 {
162  return "generic";
163 }
164 
165 bool Subject::setName(std::string name)
166 {
167  return false;
168 }
169 
170 std::map<std::string, std::string> Subject::getProperties()
171 {
172  std::map<std::string, std::string> empty;
173  return empty;
174 }
175 
176 bool Subject::setProperties(std::map<std::string, std::string> properties)
177 {
178  return true;
179 }
180 
181 std::vector<std::string> Subject::knownProperties()
182 {
183  std::vector<std::string> empty;
184  return empty;
185 }
186 
187 void Subject::select(bool isSelected)
188 {
189  DEBTRACE("Subject::select " << isSelected << " " << this);
190  set<GuiObserver*> copySet = _setObs;
191  for (set<GuiObserver *>::iterator it = copySet.begin(); it != copySet.end(); ++it)
192  {
193  GuiObserver* currOb = *it;
194  currOb->select(isSelected);
195  }
196 }
197 
198 void Subject::update(GuiEvent event,int type, Subject* son)
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 }
219 
221 {
222  return _parent;
223 }
224 
226 {
227  _parent=son;
228 }
229 
231 
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 }
313 
315 {
316 }
317 
319 {
320 }
321 
323 {
324  DEBTRACE("Subject::addSubjectReference " << getName() << " " << ref->getName());
325  SubjectReference *son = new SubjectReference(ref, this);
326  update(ADDREF, 0, son);
327 }
328 
329 void Subject::setProgress( std::string newProgress )
330 {
331  _progress = newProgress;
332 }
333 
334 // ----------------------------------------------------------------------------
335 
337  : _destructible(true)
338 {
339  //DEBTRACE("GuiObserver::GuiObserver " << this);
340  _subjectSet.clear();
341 }
342 
344 {
345  DEBTRACE("GuiObserver::~GuiObserver " << this);
346  set<Subject*> subsetcpy = _subjectSet;
347  set<Subject*>::iterator it= subsetcpy.begin();
348  for (; it != subsetcpy.end(); ++it)
349  (*it)->detach(this);
350 }
351 
352 void GuiObserver::select(bool isSelected)
353 {
354  DEBTRACE("GuiObserver::select() " << isSelected);
355 }
356 
357 void GuiObserver::update(GuiEvent event, int type, Subject* son)
358 {
359  //DEBTRACE("GuiObserver::update, event not handled " << eventName(event) << " " << type );
360 }
361 
367 {
368  if (_subjectSet.count(subject))
369  DEBTRACE("subject " << subject << " is already a subject of observer " << this << "---------------------------");
370  _subjectSet.insert(subject);
371  //DEBTRACE(this << " " << _subjectSet.size());
372 }
373 
379 {
380  if (_subjectSet.count(subject))
381  _subjectSet.erase(subject);
382  else
383  DEBTRACE("subject " << subject << " is not a subject of observer " << this << "---------------------------");
384  //DEBTRACE(this << " " << _subjectSet.size());
385 }
386 
395 {
396  return _subjectSet.size();
397 }
398 
400 {
401  _eventNameMap.clear();
402  _eventNameMap[ADD] = "ADD";
403  _eventNameMap[REMOVE] = "REMOVE";
404  _eventNameMap[CUT] = "CUT";
405  _eventNameMap[PASTE] = "PASTE";
406  _eventNameMap[ORDER] = "ORDER";
407  _eventNameMap[EDIT] = "EDIT";
408  _eventNameMap[UPDATE] = "UPDATE";
409  _eventNameMap[UPDATEPROGRESS] = "UPDATEPROGRESS";
410  _eventNameMap[SYNCHRO] = "SYNCHRO";
411  _eventNameMap[UP] = "UP";
412  _eventNameMap[DOWN] = "DOWN";
413  _eventNameMap[RENAME] = "RENAME";
414  _eventNameMap[NEWROOT] = "NEWROOT";
415  _eventNameMap[ENDLOAD] = "ENDLOAD";
416  _eventNameMap[ADDLINK] = "ADDLINK";
417  _eventNameMap[ADDCONTROLLINK] = "ADDCONTROLLINK";
418  _eventNameMap[ADDREF] = "ADDREF";
419  _eventNameMap[ADDCHILDREF] = "ADDCHILDREF";
420  _eventNameMap[REMOVECHILDREF] = "REMOVECHILDREF";
421  _eventNameMap[ASSOCIATE] = "ASSOCIATE";
422  _eventNameMap[SETVALUE] = "SETVALUE";
423  _eventNameMap[SETCASE] = "SETCASE";
424  _eventNameMap[SETSELECT] = "SETSELECT";
425  _eventNameMap[GEOMETRY] = "GEOMETRY";
426 }
427 
429 {
430  if (_eventNameMap.count(event))
431  return _eventNameMap[event];
432  else return "Unknown Event";
433 }
434 
435 // ----------------------------------------------------------------------------
436 
438 {
439 }
441 {
442 }
443 void SubjectObserver::select(bool isSelected)
444 {
445  DEBTRACE("SubjectObserver::select " << isSelected);
446  //propagate nothing
447 }
448 void SubjectObserver::update(GuiEvent event, int type, Subject* son)
449 {
450  DEBTRACE("SubjectObserver::update " << type << "," << eventName(event) << "," << son);
451  //propagate only RENAME events
452  if(event == RENAME)
453  _reference->update(event,type,son);
454 }
455 
457  : Subject(parent), _reference(ref)
458 {
459  _sobs=new SubjectObserver(this);
460  ref->attach(_sobs);
461 }
462 
464 {
465  delete _sobs;
466 }
467 
469 {
470  if (_askRegisterUndo)
471  {
472  _askRegisterUndo = false;
474  }
475  localclean(command);
476  Subject::clean(command);
477 }
478 
480 {
481  DEBTRACE("SubjectReference::localClean ");
482 }
483 
485 {
486  std::stringstream name;
487  name << "ref-->" << _reference->getName();
488  return name.str();
489 }
490 
492 {
493  return _reference;
494 }
495 
497 {
498  _parent = parent;
499 }
500 
501 // ----------------------------------------------------------------------------
502 
504  : Subject(parent), _node(node)
505 {
506  _listSubjectInputPort.clear();
507  _listSubjectOutputPort.clear();
508  _listSubjectIDSPort.clear();
509  _listSubjectODSPort.clear();
510  _listSubjectLink.clear();
511  _listSubjectControlLink.clear();
513  Dispatcher* d=Dispatcher::getDispatcher();
514  d->addObserver(this,node,"status");
515 }
516 
521 {
522  DEBTRACE("SubjectNode::~SubjectNode " << getName());
523  Dispatcher::getDispatcher()->removeObserver(this,_node,"status");
524 
525  ComposedNode* father = _node->getFather();
527  if (father)
528  try
529  {
530  // Remove child except if it's the splitter node of a ForEachLoop
531  if (dynamic_cast<ForEachLoop*>(father) == NULL ||
532  getName() != ForEachLoop::NAME_OF_SPLITTERNODE)
533  {
534  father->edRemoveChild(_node);
535  }
536  }
537  catch (YACS::Exception &e)
538  {
539  DEBTRACE("------------------------------------------------------------------------------");
540  DEBTRACE("SubjectNode::localClean: father->edRemoveChild: YACS exception " << e.what());
541  DEBTRACE("------------------------------------------------------------------------------");
542  }
543 }
544 
546 {
547  if (_askRegisterUndo)
548  {
549  _askRegisterUndo = false;
551  }
552  localclean(command);
553  Subject::clean(command);
554 }
555 
557 {
558  DEBTRACE("SubjectNode::localClean ");
560  {
561  list<SubjectLink*>::iterator its;
562  list<SubjectLink*> cpll = _listSubjectLink;
563  for (its = cpll.begin(); its != cpll.end(); ++its)
564  erase(*its);
565  }
566  {
567  list<SubjectControlLink*>::iterator its;
568  list<SubjectControlLink*> cplcl = _listSubjectControlLink;
569  for (its = cplcl.begin(); its != cplcl.end(); ++its)
570  erase(*its);
571  }
572  {
573  list<SubjectInputPort*>::iterator iti;
574  list<SubjectInputPort*> cpli = _listSubjectInputPort;
575  for(iti = cpli.begin(); iti != cpli.end(); ++iti)
576  erase(*iti);
577  }
578  {
579  list<SubjectOutputPort*>::iterator ito;
580  list<SubjectOutputPort*> cplo = _listSubjectOutputPort;
581  for(ito = cplo.begin(); ito != cplo.end(); ++ito)
582  erase(*ito);
583  }
584  {
585  list<SubjectInputDataStreamPort*>::iterator itid;
586  list<SubjectInputDataStreamPort*> cplid = _listSubjectIDSPort;
587  for(itid = cplid.begin(); itid != cplid.end(); ++itid)
588  erase(*itid);
589  }
590  {
591  list<SubjectOutputDataStreamPort*>::iterator itod;
592  list<SubjectOutputDataStreamPort*> cplod = _listSubjectODSPort;
593  for(itod = cplod.begin(); itod != cplod.end(); ++itod)
594  erase(*itod);
595  }
596  if (_parent)
597  {
598  if( SubjectBloc* sb = dynamic_cast<SubjectBloc*>(_parent) )
599  sb->removeNode(this);
600  else if( SubjectForLoop* sfl = dynamic_cast<SubjectForLoop*>(_parent) )
601  sfl->completeChildrenSubjectList( 0 );
602  else if( SubjectWhileLoop* swl = dynamic_cast<SubjectWhileLoop*>(_parent) )
603  swl->completeChildrenSubjectList( 0 );
604  else if( SubjectDynParaLoop* sdpl = dynamic_cast<SubjectDynParaLoop*>(_parent) )
605  sdpl->removeNode(this);
606  else if( SubjectSwitch* ss = dynamic_cast<SubjectSwitch*>(_parent) )
607  ss->removeNode(this);
608  }
609 }
610 
612 {
613  DEBTRACE("SubjectNode::registerUndoDestroy " << getName());
614 
615  Proc *undoProc = GuiContext::getCurrent()->getInvoc()->getUndoProc();
616  ComposedNode *oldFather = _node->getFather();
617 
618  // --- clone the node in undoProc
619 
620  ostringstream blocName;
621  blocName << "undoBloc_" << Invocator::_ctr++;
622  Bloc *undoBloc = new Bloc(blocName.str());
623  undoProc->edAddChild(undoBloc);
624  ComposedNode *newFather = undoBloc;
626  newFather->edAddChild(clone);
627 
628  // --- register a CommandCopyNode from undoProc
629 
630  Proc *proc = GuiContext::getCurrent()->getProc();
631  string position = proc->getName();
632  if (proc != dynamic_cast<Proc*>(_node->getFather())) position = proc->getChildName(_node->getFather());
633 
634  int swCase=0;
635  if (Switch* aswitch = dynamic_cast<Switch*>(_node->getFather()))
636  {
637  //the node is in a switch, save the case
638  swCase=aswitch->getRankOfNode(_node);
639  }
640 
641  CommandCopyNode *command = new CommandCopyNode(undoProc,
642  undoProc->getChildName(clone),
643  position, swCase);
644  GuiContext::getCurrent()->getInvoc()->add(command);
645 
646  // --- identify all the children service node
647 
648  list<ServiceNode*> serviceList;
649  serviceList.clear();
650  ServiceNode *service = 0;
651  ComposedNode *cnode = 0;
652  if (service = dynamic_cast<ServiceNode*>(_node))
653  serviceList.push_back(service);
654  else
655  cnode = dynamic_cast<ComposedNode*>(_node);
656  if (cnode)
657  {
658  list<Node*> children = cnode->getAllRecursiveNodes();
659  list<Node*>::iterator it = children.begin();
660  for (; it != children.end(); ++it)
661  if (service = dynamic_cast<ServiceNode*>(*it))
662  serviceList.push_back(service);
663  }
664 
665  // --- for all the children service node, find the componentInstance,
666  // see if the componentInstance has other services that will stay alive after the destroy
667  // if not, register a CommandAddComponentInstance
668  //
669 
670  list<ServiceNode*>::const_iterator ita = serviceList.begin();
671  for (; ita != serviceList.end(); ++ita)
672  {
673  bool instanceUsedOutside = false;
674  service = *ita;
675  ComponentInstance *compo = service->getComponent();
676  if (!compo) break;
677  YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
679  //list<ServiceNode*> compServiceSet;
680  set<SubjectServiceNode*>::const_iterator itset = scomp->_subServiceSet.begin();
681  for (; itset != scomp->_subServiceSet.end(); ++itset)
682  {
683  ServiceNode *sn = dynamic_cast<ServiceNode*>((*itset)->getNode());
684  if (sn && (sn != service))
685  {
686  //compServiceSet.push_back(sn);
687  instanceUsedOutside = true;
688  list<ServiceNode*>::const_iterator itb = serviceList.begin();
689  for (; itb != serviceList.end(); ++itb)
690  {
691  if ((*itb) == sn)
692  {
693  instanceUsedOutside = false;
694  break;
695  }
696  }
697  if (instanceUsedOutside)
698  break;
699  }
700  }
701 
702  string instanceName = compo->getInstanceName();
703  if (!instanceUsedOutside)
704  {
705  string compoName = compo->getCompoName();
706  string containerName = compo->getContainer()->getName();
707  CommandAddComponentInstance *comaci = new CommandAddComponentInstance(compoName, containerName, instanceName);
708  GuiContext::getCurrent()->getInvoc()->add(comaci);
709  }
710 
711  string servicePos = proc->getChildName(service);
713  instanceName);
714  GuiContext::getCurrent()->getInvoc()->add(comastc);
715  }
716 
717  // --- explore all the external links and register commands for recreation
718 
719  vector<pair<OutPort *, InPort *> > listLeaving = getNode()->getSetOfLinksLeavingCurrentScope();
720  vector<pair<InPort *, OutPort *> > listIncoming = getNode()->getSetOfLinksComingInCurrentScope();
721  vector<pair<OutPort *, InPort *> > globalList = listLeaving;
722  vector<pair<InPort *, OutPort *> >::iterator it1;
723  for (it1 = listIncoming.begin(); it1 != listIncoming.end(); ++it1)
724  {
725  pair<OutPort *, InPort *> outin = pair<OutPort *, InPort *>((*it1).second, (*it1).first);
726  globalList.push_back(outin);
727  }
728  vector<pair<OutPort *, InPort *> >::iterator it2;
729  for (it2 = globalList.begin(); it2 != globalList.end(); ++it2)
730  {
731  SubjectLink* subject = 0;
732  if (GuiContext::getCurrent()->_mapOfSubjectLink.count(*it2))
733  {
734  subject = GuiContext::getCurrent()->_mapOfSubjectLink[*it2];
735  YASSERT(subject);
736  DEBTRACE("register undo destroy link " << subject->getName());
737  subject->registerUndoDestroy();
738  }
739  }
740 
741  // --- explore all the external control links and register commands for recreation
742 
743  list<SubjectControlLink*> cplcl = getSubjectControlLinks();
744  list<SubjectControlLink*>::iterator its;
745  Node* node = getNode();
746  for (its = cplcl.begin(); its != cplcl.end(); ++its)
747  {
748  bool inside = true;
749  Node *nout = (*its)->getSubjectOutNode()->getNode();
750  Node *nin = (*its)->getSubjectInNode()->getNode();
751  inside = inside && (node == nout);
752  inside = inside && (node == nin);
753  if (!inside)
754  {
755  (*its)->registerUndoDestroy();
756  }
757  }
758 }
759 
761 {
762  DEBTRACE("SubjectNode::reparent");
763  Subject *sub = getParent(); // --- old parent subject
764  SubjectComposedNode *sop = dynamic_cast<SubjectComposedNode*>(sub);
765  YASSERT(sop);
766  SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(parent); // --- new parent subject
767  if (!snp)
768  {
769  GuiContext::getCurrent()->_lastErrorMessage = "new parent must be a composed node";
770  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
771  return false;
772  }
773  ComposedNode *cnp = dynamic_cast<ComposedNode*>(snp->getNode());
774  YASSERT(cnp);
775  Proc *proc = GuiContext::getCurrent()->getProc();
776  Proc *fromproc=_node->getProc();
777  if(proc != fromproc)
778  {
779  GuiContext::getCurrent()->_lastErrorMessage = "cut is not yet possible across procs";
780  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
781  return false;
782  }
783 
784  string position = "";
785  if (proc != dynamic_cast<Proc*>(_node))
786  position = proc->getChildName(_node);
787  else
788  position = _node->getName();
789 
790  string newParent = "";
791  if (proc != dynamic_cast<Proc*>(cnp))
792  newParent = proc->getChildName(cnp);
793  else
794  newParent = cnp->getName();
795 
796  CommandReparentNode *command = new CommandReparentNode(position, newParent);
797  if (command->execute())
798  {
799  GuiContext::getCurrent()->getInvoc()->add(command);
800  return true;
801  }
802  else delete command;
803  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
804  return false;
805 }
806 
807 void SubjectNode::recursiveUpdate(GuiEvent event, int type, Subject* son)
808 {
809  update(event, type, son);
810 }
811 
813 {
814  DEBTRACE("SubjectNode::copy");
815  Subject *sop = getParent(); // --- old parent subject
816  SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(parent); // --- new parent subject
817  if (!snp)
818  {
819  GuiContext::getCurrent()->_lastErrorMessage = "new parent must be a composed node";
820  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
821  return false;
822  }
823  ComposedNode *cnp = dynamic_cast<ComposedNode*>(snp->getNode());
824  YASSERT(cnp);
825  Proc *proc = GuiContext::getCurrent()->getProc();
826  Proc *fromproc=_node->getProc();
827  if(proc != fromproc)
828  {
829  GuiContext::getCurrent()->_lastErrorMessage = "It is not possible to paste an object from one schema to another.";
830  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
831  return false;
832  }
833 
834  string position = "";
835  if (fromproc != dynamic_cast<Proc*>(_node))
836  position = fromproc->getChildName(_node);
837  else
838  position = _node->getName();
839 
840  string newParent = "";
841  if (proc != dynamic_cast<Proc*>(cnp))
842  newParent = proc->getChildName(cnp);
843  else
844  newParent = cnp->getName();
845 
846  CommandCopyNode *command = new CommandCopyNode(fromproc, position, newParent);
847  if (command->execute())
848  {
849  GuiContext::getCurrent()->getInvoc()->add(command);
850  return true;
851  }
852  else delete command;
853  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
854  return false;
855 
856 }
857 
858 std::string SubjectNode::getName()
859 {
860  return _node->getName();
861 }
862 
864 {
865  return _node;
866 }
867 
869 {
870  return _node->isValid();
871 }
872 
873 bool SubjectNode::setName(std::string name)
874 {
875  DEBTRACE("SubjectNode::setName " << name);
876  Proc *proc = GuiContext::getCurrent()->getProc();
877  string position = "";
878  if (proc != dynamic_cast<Proc*>(_node))
879  position = proc->getChildName(_node);
880  else
881  position = _node->getName();
882  CommandRenameNode* command = new CommandRenameNode(position, name);
883  if (command->execute())
884  {
885  GuiContext::getCurrent()->getInvoc()->add(command);
886  return true;
887  }
888  else delete command;
889  return false;
890 }
891 
892 void SubjectNode::notifyObserver(Node* object,const std::string& event)
893 {
894  DEBTRACE("SubjectNode::notifyObserver " << object->getName() << " " << event);
895  TypeOfElem ntyp = ProcInvoc::getTypeOfNode(object);
896  update(UPDATE, ntyp , 0 );
897 }
898 
900 {
901  DEBTRACE("SubjectNode::saveLinks");
904  std::list<OutGate *>::const_iterator ito;
905  for(ito=loutgate.begin();ito != loutgate.end();ito++)
906  {
907  Node* n1=(*ito)->getNode();
908  Node* n2=_node;
909  DEBTRACE(n1->getName()<< " " << n2->getName());
910  }
911  std::list<InGate *>::const_iterator iti;
912  for(iti=singate.begin();iti != singate.end();iti++)
913  {
914  Node* n1=_node;
915  Node* n2=(*iti)->getNode();
916  DEBTRACE(n1->getName()<< " " << n2->getName());
917  }
918 
919  dataLinks.clear();
920  dataflowLinks.clear();
921 
922  std::vector< std::pair<OutPort *, InPort *> > listLeaving = getNode()->getSetOfLinksLeavingCurrentScope();
923  std::vector< std::pair<OutPort *, InPort *> >::iterator it3;
924  for (it3 = listLeaving.begin(); it3 != listLeaving.end(); ++it3)
925  {
926  OutPort* p1=(*it3).first;
927  InPort* p2=(*it3).second;
928  Node* n1=p1->getNode();
929  Node* n2=p2->getNode();
930  //are nodes in sequence (control link direct or indirect) ?
931  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
932  if(n1 == fath ||n2 == fath)
933  {
934  //consider it as a data only link
935  DEBTRACE("It's a data link: " << n1->getName() << "." << p1->getName() << " -> "<< n2->getName() << "." << p2->getName());
936  dataLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
937  continue;
938  }
939  while(n1->getFather() != fath) n1=n1->getFather();
940  while(n2->getFather() != fath) n2=n2->getFather();
941  OutGate* outg=n1->getOutGate();
942  if(!outg->isAlreadyInSet(n2->getInGate()))
943  {
944  DEBTRACE("It's a data link: "<<p1->getNode()->getName()<<"."<<p1->getName()<<" -> "<< p2->getNode()->getName()<<"."<<p2->getName());
945  dataLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
946  }
947  else
948  {
949  DEBTRACE("It's a dataflow link: "<<p1->getNode()->getName()<<"."<<p1->getName()<<" -> "<< p2->getNode()->getName()<<"."<<p2->getName());
950  dataflowLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
951  }
952  }
953 
954  std::vector< std::pair<InPort *, OutPort *> > listIncoming = getNode()->getSetOfLinksComingInCurrentScope();
955  std::vector< std::pair<InPort *, OutPort *> >::iterator it4;
956  for (it4 = listIncoming.begin(); it4 != listIncoming.end(); ++it4)
957  {
958  OutPort* p1=(*it4).second;
959  InPort* p2=(*it4).first;
960  Node* n1=p1->getNode();
961  Node* n2=p2->getNode();
962  //are nodes in sequence (control link direct or indirect) ?
963  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
964  if(n1 == fath ||n2 == fath)
965  {
966  //consider it as a data only link
967  DEBTRACE("It's a data link: " << n1->getName() << "." << p1->getName() << " -> "<< n2->getName() << "." << p2->getName());
968  dataLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
969  continue;
970  }
971  while(n1->getFather() != fath) n1=n1->getFather();
972  while(n2->getFather() != fath) n2=n2->getFather();
973  OutGate* outg=n1->getOutGate();
974  if(!outg->isAlreadyInSet(n2->getInGate()))
975  {
976  DEBTRACE("It's a data link: "<<p1->getNode()->getName()<<"."<<p1->getName()<<" -> "<< p2->getNode()->getName()<<"."<<p2->getName());
977  dataLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
978  }
979  else
980  {
981  DEBTRACE("It's a dataflow link: "<<p1->getNode()->getName()<<"."<<p1->getName()<<" -> "<< p2->getNode()->getName()<<"."<<p2->getName());
982  dataflowLinks.push_back(std::pair<OutPort *, InPort *>(p1,p2));
983  }
984  }
985 }
986 
988 {
989  DEBTRACE("SubjectNode::restoreLinks");
990  //restore simple data links
991  std::vector< std::pair<OutPort *, InPort *> >::iterator it3;
992  for (it3 = dataLinks.begin(); it3 != dataLinks.end(); ++it3)
993  {
994  OutPort* p1=(*it3).first;
995  InPort* p2=(*it3).second;
996  Node* n1=p1->getNode();
997  Node* n2=p2->getNode();
998  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
999  try
1000  {
1001  fath->edAddLink(p1,p2);
1002  }
1003  catch(Exception& ex)
1004  {
1005  // if a link can't be restored ignore it. It's possible when a node is reparented to a foreachloop
1006  continue;
1007  }
1009  SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n1)];
1010  SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n2)];
1013  scla->addSubjectLink(sno,spo,sni,spi);
1014  }
1015  //restore dataflow links
1016  for (it3 = dataflowLinks.begin(); it3 != dataflowLinks.end(); ++it3)
1017  {
1018  OutPort* p1=(*it3).first;
1019  InPort* p2=(*it3).second;
1020  Node* n1=p1->getNode();
1021  Node* n2=p2->getNode();
1022  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
1023  try
1024  {
1025  fath->edAddDFLink(p1,p2);
1026  }
1027  catch(Exception& ex)
1028  {
1029  // if a link can't be restored ignore it. It's possible when a node is reparented to a foreachloop
1030  continue;
1031  }
1033  SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n1)];
1034  SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n2)];
1037  scla->addSubjectLink(sno,spo,sni,spi);
1038  if(n1==fath || n2==fath) continue;
1039  while(n1->getFather() != fath) n1=n1->getFather();
1040  while(n2->getFather() != fath) n2=n2->getFather();
1041  OutGate *ogate = n1->getOutGate();
1042  InGate *igate = n2->getInGate();
1043  if (ogate->isAlreadyInSet(igate))
1044  {
1045  pair<Node*,Node*> keyLink(n1,n2);
1046  if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
1047  {
1048  SubjectNode *sfno = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n1)];
1049  SubjectNode *sfni = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(n2)];
1050  scla->addSubjectControlLink(sfno, sfni);
1051  }
1052  }
1053  }
1054 
1055  //reconnect control links
1056  // links from another node to this node
1057  std::list<OutGate *>::const_iterator it;
1058  for(it=loutgate.begin();it != loutgate.end();it++)
1059  {
1060  Node* n1=(*it)->getNode();
1061  Node* n2=_node;
1062  if(GuiContext::getCurrent()->_mapOfSubjectNode.count(n1)==0)
1063  {
1064  //It's an internal node or a destroyed one : don't treat it
1065  continue;
1066  }
1067  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
1068  if(n1 == fath)continue;
1069  if(n2 == fath)continue;
1070  //add a control link only if nodes are not in the same descendance
1071  while(n1->getFather() != fath) n1=n1->getFather();
1072  while(n2->getFather() != fath) n2=n2->getFather();
1073  OutGate *ogate = n1->getOutGate();
1074  InGate *igate = n2->getInGate();
1075  if (!ogate->isAlreadyInSet(igate))
1076  {
1077  fath->edAddCFLink(n1,n2);
1081  scla->addSubjectControlLink(subOutNode,subInNode);
1082  }
1083  }
1084 
1085  std::list<InGate *>::const_iterator it2;
1086  for(it2=singate.begin();it2 != singate.end();it2++)
1087  {
1088  Node* n1=_node;
1089  Node* n2=(*it2)->getNode();
1090  if(GuiContext::getCurrent()->_mapOfSubjectNode.count(n2)==0)
1091  {
1092  //It's an internal node or a destroyed one : don't treat it
1093  continue;
1094  }
1095  ComposedNode* fath= ComposedNode::getLowestCommonAncestor(n1,n2);
1096  if(n1 == fath)continue;
1097  if(n2 == fath)continue;
1098  //add a control link only if nodes are not in the same descendance
1099  while(n1->getFather() != fath) n1=n1->getFather();
1100  while(n2->getFather() != fath) n2=n2->getFather();
1101  OutGate *ogate = n1->getOutGate();
1102  InGate *igate = n2->getInGate();
1103  if (!ogate->isAlreadyInSet(igate))
1104  {
1105  fath->edAddCFLink(n1,n2);
1109  scla->addSubjectControlLink(subOutNode,subInNode);
1110  }
1111  }
1112 }
1113 
1114 bool SubjectNode::putInComposedNode(std::string name,std::string type, bool toSaveRestoreLinks)
1115 {
1116  Proc *proc = GuiContext::getCurrent()->getProc();
1117  string position = "";
1118  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
1119 
1120  CommandPutInComposedNode *command = new CommandPutInComposedNode(position, name, type, toSaveRestoreLinks);
1121  if (command->execute())
1122  {
1123  GuiContext::getCurrent()->getInvoc()->add(command);
1124  return true;
1125  }
1126  else delete command;
1127  DEBTRACE(GuiContext::getCurrent()->_lastErrorMessage);
1128  return false;
1129 }
1130 
1132  std::string name)
1133 {
1134  string theName = name;
1135  if (name.empty()) theName =port->getName();
1136  DEBTRACE("SubjectNode::addSubjectInputPort "<< theName);
1137  SubjectInputPort *son = new SubjectInputPort(port, this);
1138  GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)] = son;
1139  _listSubjectInputPort.push_back(son);
1140  if (!name.empty()) son->setName(name);
1141  update(ADD, INPUTPORT ,son);
1142  YACS::ENGINE::TypeCode *typcod = port->edGetType();
1143  if (!GuiContext::getCurrent()->getSubjectProc()->addComSubjectDataType(typcod, typcod->name()))
1144  GuiContext::getCurrent()->getSubjectProc()->addSubjectDataType(typcod, typcod->name()); // --- new type of forEachLoop
1145  return son;
1146 }
1147 
1148 void SubjectNode::update( GuiEvent event, int type, Subject* son )
1149 {
1150  Subject::update( event, type, son );
1151 
1152  // remove subject data type if necessary
1153  YACS::HMI::SubjectDataPort* aSPort = dynamic_cast< YACS::HMI::SubjectDataPort* >( son );
1154 // if ( aSPort && event == REMOVE )
1155 // {
1156 // YACS::ENGINE::DataPort* aEPort = aSPort->getPort();
1157 // if ( aEPort )
1158 // {
1159 // YACS::ENGINE::TypeCode* aTypeCode = aEPort->edGetType();
1160 // if ( aTypeCode )
1161 // GuiContext::getCurrent()->getSubjectProc()->removeSubjectDataType( aTypeCode );
1162 // }
1163 // }
1164 }
1165 
1166 void SubjectNode::setExecState(int execState)
1167 {
1168  _execState = execState;
1170 }
1171 
1173  std::string name)
1174 {
1175  string theName = name;
1176  if (name.empty()) theName =port->getName();
1177  DEBTRACE("SubjectNode::addSubjectOutputPort "<< theName);
1178  SubjectOutputPort *son = new SubjectOutputPort(port, this);
1179  GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)] = son;
1180  _listSubjectOutputPort.push_back(son);
1181  if (!name.empty()) son->setName(name);
1182  update(ADD, OUTPUTPORT ,son);
1183  YACS::ENGINE::TypeCode *typcod = port->edGetType();
1185  return son;
1186 }
1187 
1189  std::string name)
1190 {
1191  string theName = name;
1192  if (name.empty()) theName =port->getName();
1193  DEBTRACE("SubjectNode::addSubjectIDSPort "<< theName);
1195  GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)] = son;
1196  _listSubjectIDSPort.push_back(son);
1197  if (!name.empty()) son->setName(name);
1199  YACS::ENGINE::TypeCode *typcod = port->edGetType();
1201  return son;
1202 }
1203 
1204 
1206  std::string name)
1207 {
1208  string theName = name;
1209  if (name.empty()) theName =port->getName();
1210  DEBTRACE("SubjectNode::addSubjectODSPort "<< theName);
1212  GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)] = son;
1213  _listSubjectODSPort.push_back(son);
1214  if (!name.empty()) son->setName(name);
1216  YACS::ENGINE::TypeCode *typcod = port->edGetType();
1218  return son;
1219 }
1220 
1222 {
1223  DEBTRACE("SubjectNode::tryCreateLink " << subOutNode->getName() << " " << subInNode->getName());
1224  Proc *proc = GuiContext::getCurrent()->getProc();
1225  Node *outNode = subOutNode->getNode();
1226  string outNodePos = proc->getChildName(outNode);
1227  Node *inNode = subInNode->getNode();
1228  string inNodePos = proc->getChildName(inNode);
1229  CommandAddControlLink *command = new CommandAddControlLink(outNodePos, inNodePos);
1230  if (command->execute())
1231  {
1232  GuiContext::getCurrent()->getInvoc()->add(command);
1233  return true;
1234  }
1235  else
1236  {
1237  delete command;
1238  return false;
1239  }
1240 }
1241 
1243 {
1244  DEBTRACE("SubjectNode::removeExternalLinks " << getName());
1245  std::vector< std::pair<OutPort *, InPort *> > listLeaving = getNode()->getSetOfLinksLeavingCurrentScope();
1246  std::vector< std::pair<InPort *, OutPort *> > listIncoming = getNode()->getSetOfLinksComingInCurrentScope();
1247  std::vector< std::pair<OutPort *, InPort *> > globalList = listLeaving;
1248  std::vector< std::pair<InPort *, OutPort *> >::iterator it1;
1249  for (it1 = listIncoming.begin(); it1 != listIncoming.end(); ++it1)
1250  {
1251  std::pair<OutPort *, InPort *> outin = std::pair<OutPort *, InPort *>((*it1).second, (*it1).first);
1252  globalList.push_back(outin);
1253  }
1254  std::vector< std::pair<OutPort *, InPort *> >::iterator it2;
1255  for (it2 = globalList.begin(); it2 != globalList.end(); ++it2)
1256  {
1257  SubjectLink* subject = 0;
1258  if (GuiContext::getCurrent()->_mapOfSubjectLink.count(*it2))
1259  {
1260  subject = GuiContext::getCurrent()->_mapOfSubjectLink[*it2];
1261  YASSERT(subject);
1262  DEBTRACE("link to remove " << subject->getName());
1263  erase(subject);
1265  }
1266  else
1267  {
1268  DEBTRACE("------------------------------------------------------------------------------");
1269  DEBTRACE("SubjectNode::removeExternalLinks(): an external link not in map...");
1270  DEBTRACE("------------------------------------------------------------------------------");
1271  }
1272  }
1273 }
1274 
1276 {
1277  DEBTRACE("SubjectNode::removeExternalControlLinks " << getName());
1278  list<SubjectControlLink*> cplcl = getSubjectControlLinks();
1279  list<SubjectControlLink*>::iterator its;
1280  Node* node = getNode();
1281  for (its = cplcl.begin(); its != cplcl.end(); ++its)
1282  {
1283  bool inside = true;
1284  Node *nout = (*its)->getSubjectOutNode()->getNode();
1285  Node *nin = (*its)->getSubjectInNode()->getNode();
1286  inside = inside && (node == nout);
1287  inside = inside && (node == nin);
1288  if (!inside)
1289  Subject::erase(*its);
1290  }
1291 }
1292 
1293 std::map<std::string, std::string> SubjectNode::getProperties()
1294 {
1295  return _node->getPropertyMap();
1296 }
1297 
1298 bool SubjectNode::setProperties(std::map<std::string, std::string> properties)
1299 {
1300  Proc *proc = GuiContext::getCurrent()->getProc();
1301  string position = "";
1302  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
1303 
1304  CommandSetNodeProperties *command = new CommandSetNodeProperties(position, properties);
1305  if (command->execute())
1306  {
1307  GuiContext::getCurrent()->getInvoc()->add(command);
1308  return true;
1309  }
1310  else delete command;
1311  return false;
1312 }
1313 
1314 // ----------------------------------------------------------------------------
1315 
1317  Subject *parent)
1318  : SubjectNode(composedNode, parent), _composedNode(composedNode)
1319 {
1320 }
1321 
1326 {
1327  DEBTRACE("SubjectComposedNode::~SubjectComposedNode " << getName());
1328 }
1329 
1331 {
1332  if (_askRegisterUndo)
1333  {
1334  _askRegisterUndo = false;
1336  }
1337  localclean(command);
1338  SubjectNode::clean(command);
1339 }
1340 
1342 {
1343  DEBTRACE("SubjectComposedNode::localClean ");
1344 }
1345 
1347  std::string compo,
1348  std::string type,
1349  std::string name,
1350  bool newCompoInst)
1351 {
1352  DEBTRACE("SubjectComposedNode::addNode("<<catalog<<","<<compo<<","<<type<<","<<name<<")");
1353  SubjectNode* body = 0;
1354  GuiContext::getCurrent()->_lastErrorMessage = "YACS Internal Error: SubjectComposedNode::addNode";
1355  return body;
1356 }
1357 
1359  std::string compo,
1360  std::string type,
1361  std::string name,
1362  bool newCompoInst,
1363  int swCase)
1364 {
1365  Proc *proc = GuiContext::getCurrent()->getProc();
1366  string position = "";
1367  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
1369  compo,
1370  type,
1371  position,
1372  name,
1373  newCompoInst,
1374  swCase);
1375  if (command->execute())
1376  {
1377  GuiContext::getCurrent()->getInvoc()->add(command);
1378  Node * node = command->getNode();
1379  return command->getSubjectNode();
1380  }
1381  else delete command;
1382  return 0;
1383 }
1384 
1386  std::string name,
1387  YACS::ENGINE::Catalog *catalog,
1388  std::string compo,
1389  std::string type)
1390 {
1391  string theName = name;
1392  if (name.empty()) theName =node->getName();
1393  DEBTRACE("SubjectComposedNode::addSubjectNode "<< theName);
1394  TypeOfElem ntyp = ProcInvoc::getTypeOfNode(node);
1395  DEBTRACE("TypeOfNode: " << ntyp);
1396  SubjectNode *son = 0;
1397  switch(ntyp)
1398  {
1399  case BLOC:
1400  son = new SubjectBloc(dynamic_cast<YACS::ENGINE::Bloc*>(node), this);
1401  break;
1402  case PYTHONNODE:
1403  son = new SubjectPythonNode(dynamic_cast<YACS::ENGINE::PythonNode*>(node), this);
1404  break;
1405  case PYFUNCNODE:
1406  son = new SubjectPyFuncNode(dynamic_cast<YACS::ENGINE::PyFuncNode*>(node), this);
1407  break;
1408  case CORBANODE:
1409  son = new SubjectCORBANode(dynamic_cast<YACS::ENGINE::CORBANode*>(node), this);
1410  break;
1411  case CPPNODE:
1412  son = new SubjectCppNode(dynamic_cast<YACS::ENGINE::CppNode*>(node), this);
1413  break;
1414  case SALOMENODE:
1415  son = new SubjectSalomeNode(dynamic_cast<YACS::ENGINE::SalomeNode*>(node), this);
1416  break;
1417  case SALOMEPYTHONNODE:
1418  son = new SubjectSalomePythonNode(dynamic_cast<YACS::ENGINE::SalomePythonNode*>(node), this);
1419  break;
1420  case XMLNODE:
1421  son = new SubjectXmlNode(dynamic_cast<YACS::ENGINE::XmlNode*>(node), this);
1422  break;
1423  case SPLITTERNODE:
1424  son = new SubjectSplitterNode(dynamic_cast<YACS::ENGINE::SplitterNode*>(node), this);
1425  break;
1426  case PRESETNODE:
1427  son = new SubjectPresetNode(dynamic_cast<YACS::ENGINE::PresetNode*>(node), this);
1428  break;
1429  case OUTNODE:
1430  son = new SubjectOutNode(dynamic_cast<YACS::ENGINE::OutNode*>(node), this);
1431  break;
1432  case STUDYINNODE:
1433  son = new SubjectStudyInNode(dynamic_cast<YACS::ENGINE::StudyInNode*>(node), this);
1434  break;
1435  case STUDYOUTNODE:
1436  son = new SubjectStudyOutNode(dynamic_cast<YACS::ENGINE::StudyOutNode*>(node), this);
1437  break;
1438  case FORLOOP:
1439  son = new SubjectForLoop(dynamic_cast<YACS::ENGINE::ForLoop*>(node), this);
1440  break;
1441  case WHILELOOP:
1442  son = new SubjectWhileLoop(dynamic_cast<YACS::ENGINE::WhileLoop*>(node), this);
1443  break;
1444  case SWITCH:
1445  son = new SubjectSwitch(dynamic_cast<YACS::ENGINE::Switch*>(node), this);
1446  break;
1447  case FOREACHLOOP:
1448  son = new SubjectForEachLoop(dynamic_cast<YACS::ENGINE::ForEachLoop*>(node), this);
1449  break;
1450  case OPTIMIZERLOOP:
1451  son = new SubjectOptimizerLoop(dynamic_cast<YACS::ENGINE::OptimizerLoop*>(node), this);
1452  break;
1453  default:
1454  throw YACS::Exception("Not implemented");
1455  //YASSERT(0);
1456  }
1457  YASSERT(son);
1458  GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(node)] = son;
1460  if (!name.empty()) son->setName(name);
1462  update(ADD, ntyp ,son);
1463  if (SubjectServiceNode *service = dynamic_cast<SubjectServiceNode*>(son))
1464  if (catalog && !compo.empty() && !type.empty()) // --- clone from catalog: set component
1465  service->setComponentFromCatalog(catalog,compo,type);
1466  else
1467  service->setComponent();
1468  return son;
1469 }
1470 
1472 {
1473 }
1474 
1476 {
1477  list<Node *> setOfNode= _composedNode->edGetDirectDescendants();
1478  if (ForEachLoop *feloop = dynamic_cast<ForEachLoop*>(_composedNode))
1479  {
1480  Node *node2Insert=feloop->getChildByName(ForEachLoop::NAME_OF_SPLITTERNODE);
1481  if(find(setOfNode.begin(),setOfNode.end(),node2Insert)==setOfNode.end())
1482  setOfNode.push_back(node2Insert);
1483  }
1484  for(list<Node *>::iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
1485  {
1486  try
1487  {
1488  SubjectNode * son = addSubjectNode(*iter);
1489  son->loadChildren();
1490  }
1491  catch(YACS::Exception& ex)
1492  {
1493  std::cerr << "Unknown type of node" << std::endl;
1494  }
1495  }
1496  list<InputPort*> listInputPorts = _composedNode->getLocalInputPorts();
1497  list<OutputPort*> listOutputPorts = _composedNode->getLocalOutputPorts();
1498  list<InputDataStreamPort*> listIDSPorts = _composedNode->getSetOfInputDataStreamPort();
1499  list<OutputDataStreamPort*> listODSPorts = _composedNode->getSetOfOutputDataStreamPort();
1500  list<InputPort*>::const_iterator iti;
1501  for (iti = listInputPorts.begin(); iti != listInputPorts.end(); ++iti)
1502  addSubjectInputPort(*iti);
1503  list<OutputPort*>::const_iterator ito;
1504  for (ito = listOutputPorts.begin(); ito != listOutputPorts.end(); ++ito)
1505  addSubjectOutputPort(*ito);
1506 }
1507 
1509  SubjectDataPort *spo,
1510  SubjectNode *sni,
1511  SubjectDataPort *spi)
1512 {
1513  DEBTRACE("SubjectComposedNode::addSubjectLink");
1514  OutPort *outp = dynamic_cast<OutPort*>(spo->getPort());
1515  InPort *inp = dynamic_cast<InPort*>(spi->getPort());
1516  pair<OutPort*,InPort*> keyLink(outp,inp);
1517  //Don't create a new subject if it already exists
1518  if(GuiContext::getCurrent()->_mapOfSubjectLink.count(keyLink)!=0)
1519  return GuiContext::getCurrent()->_mapOfSubjectLink[keyLink];
1520 
1521  SubjectLink *son = new SubjectLink(sno, spo, sni, spi, this);
1522  GuiContext::getCurrent()->_mapOfSubjectLink[keyLink] = son;
1523  _listSubjectLink.push_back(son);
1524  spo->addSubjectLink(son);
1525  spi->addSubjectLink(son);
1526  update(ADDLINK, DATALINK, son);
1527  spi->update(UPDATE, DATALINK, spo);
1528  spo->update(UPDATE, DATALINK, spi);
1529  DEBTRACE("addSubjectLink: " << getName() << " " << son->getName());
1530  return son;
1531 }
1532 
1534 {
1535  DEBTRACE("removeLink: " << link->getName());
1536 
1537  OutPort *outp = dynamic_cast<OutPort*>(link->getSubjectOutPort()->getPort());
1538  InPort *inp = dynamic_cast<InPort*>(link->getSubjectInPort()->getPort());
1539  pair<OutPort*,InPort*> keyLink(outp,inp);
1540  if (GuiContext::getCurrent()->_mapOfSubjectLink.count(keyLink))
1541  {
1542  DEBTRACE(outp->getName() << " " << inp->getName());
1543  GuiContext::getCurrent()->_mapOfSubjectLink.erase(keyLink);
1544  }
1545 
1546  link->getSubjectOutPort()->removeSubjectLink(link);
1547  link->getSubjectInPort()->removeSubjectLink(link);
1548  _listSubjectLink.remove(link);
1549 }
1550 
1552  SubjectNode *sni)
1553 {
1554  Node *outn = sno->getNode();
1555  Node *inn = sni->getNode();
1556  pair<Node*,Node*> keyLink(outn,inn);
1557  //Don't create a new subject if it already exists
1558  if(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink)!=0)
1560 
1561  SubjectControlLink *son = new SubjectControlLink(sno, sni, this);
1563  _listSubjectControlLink.push_back(son);
1564  sno->addSubjectControlLink(son);
1565  sni->addSubjectControlLink(son);
1567  DEBTRACE("addSubjectControlLink: " << getName() << " " << son->getName());
1568  return son;
1569 }
1570 
1572 {
1573  DEBTRACE("removeSubjectControlLink: " << getName());
1574 
1575  Node *outn = link->getSubjectOutNode()->getNode();
1576  Node *inn = link->getSubjectInNode()->getNode();
1577  pair<Node*,Node*> keyLink(outn,inn);
1578  if (GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
1579  {
1580  DEBTRACE(outn->getName() << " " << inn->getName());
1582  }
1583 
1586  _listSubjectControlLink.remove(link);
1587 }
1588 
1590 {
1591  DEBTRACE("SubjectComposedNode::removeExternalControlLinks " << getName());
1592  list<SubjectControlLink*> cplcl = getSubjectControlLinks();
1593  list<SubjectControlLink*>::iterator its;
1594  ComposedNode *cnode = dynamic_cast<ComposedNode*>(getNode());
1595  for (its = cplcl.begin(); its != cplcl.end(); ++its)
1596  {
1597  bool inside = true;
1598  Node *nout = (*its)->getSubjectOutNode()->getNode();
1599  Node *nin = (*its)->getSubjectInNode()->getNode();
1600  inside = inside && cnode->isInMyDescendance(nout); // --- 0 if nout is outside
1601  inside = inside && cnode->isInMyDescendance(nin); // --- 0 if nin is outside
1602  if (!inside)
1603  Subject::erase(*its);
1604  }
1605 }
1606 
1608 {
1609 }
1610 
1620 {
1621  list<Node *> setOfNode= _composedNode->edGetDirectDescendants();
1622  for(list<Node *>::iterator iter=setOfNode.begin();iter!=setOfNode.end();iter++)
1623  {
1624  ComposedNode *cnSon = dynamic_cast<ComposedNode*>(*iter);
1625  if (cnSon)
1626  {
1627  SubjectNode *subSon = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(*iter)];
1628  YASSERT(subSon);
1629  SubjectComposedNode *subCnSon = dynamic_cast<SubjectComposedNode*>(subSon);
1630  YASSERT(subCnSon);
1631  subCnSon->loadLinks();
1632  }
1633  }
1634 
1635  std::vector<std::pair<OutPort*,InPort*> > setOfLinks = _composedNode->getSetOfInternalLinks();
1636  std::vector<std::pair<OutPort*,InPort*> >::iterator itp;
1637  for (itp = setOfLinks.begin(); itp != setOfLinks.end(); ++itp)
1638  if (!GuiContext::getCurrent()->_mapOfSubjectLink.count(*itp))
1639  {
1640  OutPort *outp = (*itp).first;
1641  InPort *inp = (*itp).second;
1642  Node *outn = outp->getNode();
1643  Node *inn = inp->getNode();
1644  DEBTRACE(outn->getName()<<"."<<outp->getName()<<"->"<<inn->getName()<<"."<<inp->getName());
1645  SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(outn)];
1646  SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[static_cast<Node*>(inn)];
1649  addSubjectLink(sno,spo,sni,spi);
1650  }
1651 
1652  std::list<Node*> setOfNodes = _composedNode->edGetDirectDescendants();
1653  std::list<Node*>::const_iterator itn;
1654  for(itn = setOfNodes.begin(); itn != setOfNodes.end(); ++itn)
1655  {
1657  OutGate* outgate = (*itn)->getOutGate();
1658  std::list<InGate*> setIngate = outgate->edSetInGate();
1659  std::list<InGate*>::const_iterator itg;
1660  for(itg = setIngate.begin(); itg != setIngate.end(); ++itg)
1661  {
1662  Node* inNode = (*itg)->getNode();
1664  if(sno && sni)
1665  addSubjectControlLink(sno,sni);
1666  }
1667  }
1668 }
1669 
1671 
1682 {
1683  Node* node1 = snode1->getNode();
1684  Node* node2 = snode2->getNode();
1685 
1686  ComposedNode *node = ComposedNode::getLowestCommonAncestor(node1->getFather(), node2->getFather());
1688  return snode;
1689 }
1690 
1695 {
1696  return false;
1697 }
1698 
1703 {
1704  return "";
1705 }
1706 
1707 
1708 // ----------------------------------------------------------------------------
1709 
1711  : SubjectComposedNode(bloc, parent), _bloc(bloc)
1712 {
1713  _children.clear();
1714 }
1715 
1720 {
1721  DEBTRACE("SubjectBloc::~SubjectBloc " << getName());
1722 }
1723 
1725 {
1726  if (_askRegisterUndo)
1727  {
1728  _askRegisterUndo = false;
1730  }
1731  localclean(command);
1732  SubjectComposedNode::clean(command);
1733 }
1734 
1736 {
1737  DEBTRACE("SubjectBloc::localClean ");
1738  set<SubjectNode*>::iterator it;
1739  set<SubjectNode*> copyChildren = _children;
1740  for (it = copyChildren.begin(); it !=copyChildren.end(); ++it)
1741  erase(*it);
1742 }
1743 
1745  std::string compo,
1746  std::string type,
1747  std::string name,
1748  bool newCompoInst)
1749 {
1750  DEBTRACE("SubjectBloc::addNode( " << catalog << ", " << compo << ", " << type << ", " << name << " )");
1751  SubjectNode* child = createNode(catalog, compo, type, name, newCompoInst);
1752  return child;
1753 }
1754 
1756 {
1757  if (isCut)
1758  removeNode(son);
1759  else
1761 }
1762 
1764 {
1765  _children.insert(son);
1766 }
1767 
1769 {
1770  _children.erase(child);
1771 }
1772 
1774 {
1775  SubjectNode* aChild = 0;
1776 
1777  if (node)
1778  {
1779  set<SubjectNode*>::const_iterator it = _children.begin();
1780  for ( ; it != _children.end(); it++ )
1781  if ( (*it)->getNode() == node )
1782  {
1783  aChild = (*it);
1784  break;
1785  }
1786  }
1787 
1788  return aChild;
1789 }
1790 
1791 void SubjectBloc::recursiveUpdate(GuiEvent event, int type, Subject* son)
1792 {
1793  update(event, type, son);
1794  set<SubjectNode*>::iterator it = _children.begin();
1795  for (; it != _children.end(); ++it)
1796  (*it)->recursiveUpdate(event, type, son);
1797 }
1798 
1799 
1800 // ----------------------------------------------------------------------------
1801 
1803  : SubjectBloc(proc, parent), _proc(proc)
1804 {
1805  _postEraseList.clear();
1806 }
1807 
1809 {
1810  DEBTRACE("SubjectProc::~SubjectProc " << getName());
1811 }
1812 
1814 {
1815  if (_askRegisterUndo)
1816  {
1817  _askRegisterUndo = false;
1819  }
1820  localclean(command);
1821  SubjectBloc::clean(command);
1822 }
1823 
1825 {
1826  DEBTRACE("SubjectProc::localClean ");
1827 }
1828 
1830 {
1831  DEBTRACE("SubjectProc::cleanPostErase");
1832  for (int i=0; i<_postEraseList.size(); i++)
1833  {
1834  DEBTRACE("cleanPostErase " << _postEraseList[i]->getName());
1835  erase(_postEraseList[i],0, true); // --- true: do not call recursively erase
1836  }
1837  _postEraseList.clear();
1838 }
1839 
1841 {
1842  DEBTRACE("SubjectProc::loadProc " << getName());
1843  loadTypes();
1844  loadContainers();
1845  loadComponents();
1846  loadChildren();
1847  loadLinks();
1848 }
1849 
1851 
1855 {
1856  Catalog* builtinCatalog = getSALOMERuntime()->getBuiltinCatalog();
1857  std::map<std::string, TypeCode *>::iterator pt;
1858  for(pt=builtinCatalog->_typeMap.begin();pt!=builtinCatalog->_typeMap.end();pt++)
1859  {
1860  addSubjectDataType((*pt).second , (*pt).first);
1861  }
1862  for(pt=_proc->typeMap.begin();pt!=_proc->typeMap.end();pt++)
1863  {
1864  addSubjectDataType((*pt).second , (*pt).first);
1865  }
1866 }
1867 
1876 {
1877  Proc* aProc = GuiContext::getCurrent()->getProc();
1878  for (map<string, ComponentInstance*>::const_iterator itComp = aProc->componentInstanceMap.begin();
1879  itComp != aProc->componentInstanceMap.end(); ++itComp)
1880  {
1881  GuiContext::getCurrent()->_mapOfLastComponentInstance[itComp->second->getCompoName()]=itComp->second;
1882 
1883  if ( GuiContext::getCurrent()->_mapOfSubjectComponent.find((*itComp).second)
1884  ==
1886  { // engine object for component already exists => add only a subject for it
1887  addSubjectComponent((*itComp).second);
1888  }
1889  }
1890 }
1891 
1898 {
1899  Proc* aProc = GuiContext::getCurrent()->getProc();
1900  for (map<string, Container*>::const_iterator itCont = aProc->containerMap.begin(); itCont != aProc->containerMap.end(); ++itCont)
1902  // engine object for container already exists => add only a subject for it
1903  addSubjectContainer((*itCont).second,(*itCont).second->getName());
1904 }
1905 
1906 SubjectComponent* SubjectProc::addComponent(std::string compoName, std::string containerName)
1907 {
1908  DEBTRACE("SubjectProc::addComponent " << compoName << " " << containerName);
1909  CommandAddComponentInstance *command = new CommandAddComponentInstance(compoName, containerName);
1910  if (command->execute())
1911  {
1912  GuiContext::getCurrent()->getInvoc()->add(command);
1913  return command->getSubjectComponent();
1914  }
1915  else delete command;
1916  return 0;
1917 }
1918 
1919 SubjectContainerBase *SubjectProc::addContainer(std::string name, std::string ref)
1920 {
1921  DEBTRACE("SubjectProc::addContainer " << name << " " << ref);
1922  if (! GuiContext::getCurrent()->getProc()->containerMap.count(name))
1923  {
1924  CommandAddContainer *command(new CommandAddContainer(name,ref));
1925  if (command->execute())
1926  {
1927  GuiContext::getCurrent()->getInvoc()->add(command);
1928  return command->getSubjectContainer();
1929  }
1930  else
1931  delete command;
1932  }
1933  else GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
1934  return 0;
1935 }
1936 
1938 {
1939  DEBTRACE("SubjectProc::addContainer " << name << " " << ref);
1940  if (! GuiContext::getCurrent()->getProc()->containerMap.count(name))
1941  {
1942  CommandAddHPContainer *command(new CommandAddHPContainer(name,ref));
1943  if (command->execute())
1944  {
1945  GuiContext::getCurrent()->getInvoc()->add(command);
1946  return command->getSubjectContainer();
1947  }
1948  else
1949  delete command;
1950  }
1951  else GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
1952  return 0;
1953 }
1954 
1955 bool SubjectProc::addDataType(YACS::ENGINE::Catalog* catalog, std::string typeName)
1956 {
1957  DEBTRACE("SubjectProc::addDataType " << typeName);
1958  CommandAddDataTypeFromCatalog *command = new CommandAddDataTypeFromCatalog(catalog, typeName);
1959  if (command->execute())
1960  {
1961  DEBTRACE("new datatype " << typeName);
1962  GuiContext::getCurrent()->getInvoc()->add(command);
1963  return true;
1964  }
1965  else delete command;
1966  return 0;
1967 }
1968 
1970 {
1971  DEBTRACE("SubjectProc::addSubjectComponent " << compo->getInstanceName());
1972  SubjectComponent *son = new SubjectComponent(compo, this);
1974  update(ADD, COMPONENT, son);
1975  //son->setContainer();
1976  return son;
1977 }
1978 
1980 {
1981  DEBTRACE("SubjectProc::addSubjectContainer " << name);
1983  // In edition mode do not clone containers
1984  // cont->attachOnCloning(); // agy : do not use _attachOnCloning attribute in edition mode. This attribute should be used now at runtime.
1986  update(ADD, CONTAINER, son);
1987  return son;
1988 }
1989 
1994 {
1995  string typeName = type->name();
1996  DEBTRACE("SubjectProc::addComSubjectDataType " << typeName);
1997  SubjectDataType* son = 0;
1998  if (GuiContext::getCurrent()->isLoading())
1999  son = addSubjectDataType(type,alias); // no sub command registration
2000  else
2001  {
2004  typeName);
2005  if (command->execute())
2006  GuiContext::getCurrent()->getInvoc()->add(command);
2007  else delete command;
2008  }
2009  return son;
2010 }
2011 
2012 
2014 {
2015  string typeName = type->name();
2016  DEBTRACE("SubjectProc::addSubjectDataType " << typeName);
2017  Proc* proc = GuiContext::getCurrent()->getProc();
2018  SubjectDataType* son = 0;
2019  if (! proc->typeMap.count(typeName))
2020  proc->typeMap[ typeName ] = type->clone();
2021  else
2022  proc->typeMap[ typeName ]->incrRef();
2023  if (! GuiContext::getCurrent()->_mapOfSubjectDataType.count(typeName))
2024  {
2025  son = new SubjectDataType(type, this, alias);
2026  GuiContext::getCurrent()->_mapOfSubjectDataType[typeName] = son;
2027  update(ADD, DATATYPE, son);
2028  }
2029  else
2030  GuiContext::getCurrent()->_lastErrorMessage = "Typecode " + typeName + " was already added in proc";
2031  return son;
2032 }
2033 
2034 void SubjectProc::removeSubjectDataType(std::string typeName)
2035 {
2036  Proc* proc = GuiContext::getCurrent()->getProc();
2037  YASSERT(proc->typeMap.count(typeName));
2038  YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataType.count(typeName));
2039  TypeCode* aTypeCode = proc->typeMap[typeName];
2041  unsigned int aRefCnt = aTypeCode->getRefCnt();
2042  DEBTRACE("SubjectProc::removeSubjectDataType: " << typeName << " " << aRefCnt);
2043  GuiContext::getCurrent()->_mapOfSubjectDataType.erase(typeName);
2044  proc->typeMap.erase(typeName);
2045  erase(aSDataType); // do all the necessary updates
2046  aTypeCode->decrRef();
2047 }
2048 
2050 {
2051  YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(scont->getContainer()));
2052  erase(scont); // do all the necessary updates
2053 }
2054 
2055 
2056 // ----------------------------------------------------------------------------
2057 
2059  Subject *parent)
2060  : SubjectNode(elementaryNode, parent), _elementaryNode(elementaryNode)
2061 {
2062 }
2063 
2068 {
2069  DEBTRACE("SubjectElementaryNode::~SubjectElementaryNode " << getName());
2070 }
2071 
2073 {
2074  if (_askRegisterUndo)
2075  {
2076  _askRegisterUndo = false;
2078  }
2079  localclean(command);
2080  SubjectNode::clean(command);
2081 }
2082 
2084 {
2085  DEBTRACE("SubjectElementaryNode::localClean ");
2086 }
2087 
2089 {
2090  update(event, type, son);
2091 }
2092 
2093 SubjectDataPort* SubjectElementaryNode::addInputPort(YACS::ENGINE::Catalog *catalog, std::string type, std::string name)
2094 {
2095  DEBTRACE("SubjectElementaryNode::addInputPort( " << catalog << ", " << type << ", " << name << " )");
2096  Proc *proc = GuiContext::getCurrent()->getProc();
2097  string position = "";
2098  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
2099  else YASSERT(0);
2101  type,
2102  position,
2103  name);
2104  if (command->execute())
2105  {
2106  GuiContext::getCurrent()->getInvoc()->add(command);
2107  SubjectInputPort *son = command->getSubjectInputPort();
2108  return son;
2109  }
2110  else delete command;
2111  return 0;
2112 }
2113 
2115 {
2116  DEBTRACE("SubjectElementaryNode::addOutputPort( " << catalog << ", " << type << ", " << name << " )");
2117  Proc *proc = GuiContext::getCurrent()->getProc();
2118  string position = "";
2119  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
2120  else YASSERT(0);
2122  type,
2123  position,
2124  name);
2125  if (command->execute())
2126  {
2127  GuiContext::getCurrent()->getInvoc()->add(command);
2128  SubjectOutputPort *son = command->getSubjectOutputPort();
2129  return son;
2130  }
2131  else delete command;
2132  return 0;
2133 }
2134 
2135 SubjectDataPort* SubjectElementaryNode::addIDSPort(YACS::ENGINE::Catalog *catalog, std::string type, std::string name)
2136 {
2137  DEBTRACE("SubjectElementaryNode::addIDSPort( " << catalog << ", " << type << ", " << name << " )");
2138  Proc *proc = GuiContext::getCurrent()->getProc();
2139  string position = "";
2140  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
2141  else YASSERT(0);
2143  type,
2144  position,
2145  name);
2146  if (command->execute())
2147  {
2148  GuiContext::getCurrent()->getInvoc()->add(command);
2150  return son;
2151  }
2152  else delete command;
2153  return 0;
2154 }
2155 
2156 SubjectDataPort* SubjectElementaryNode::addODSPort(YACS::ENGINE::Catalog *catalog, std::string type, std::string name)
2157 {
2158  DEBTRACE("SubjectElementaryNode::addODSPort( " << catalog << ", " << type << ", " << name << " )");
2159  Proc *proc = GuiContext::getCurrent()->getProc();
2160  string position = "";
2161  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
2162  else YASSERT(0);
2164  type,
2165  position,
2166  name);
2167  if (command->execute())
2168  {
2169  GuiContext::getCurrent()->getInvoc()->add(command);
2171  return son;
2172  }
2173  else delete command;
2174  return 0;
2175 }
2176 
2178 {
2179  DEBTRACE("SubjectElementaryNode::OrderDataPorts");
2180  Proc *proc = GuiContext::getCurrent()->getProc();
2181  string position = "";
2182  if (proc != dynamic_cast<Proc*>(_node)) position = proc->getChildName(_node);
2183  else YASSERT(0);
2184 
2185  if (!portToMove) return false;
2186  string nameToMove = portToMove->getName();
2187 
2188  Command *command = 0;
2189  bool isInput = dynamic_cast<SubjectInputPort*>(portToMove);
2190  if (isInput)
2191  command = new CommandOrderInputPorts(position, nameToMove, isUp);
2192  else
2193  command = new CommandOrderOutputPorts(position, nameToMove, isUp);
2194 
2195  if (command->execute())
2196  {
2197  GuiContext::getCurrent()->getInvoc()->add(command);
2198  return true;
2199  }
2200  return false;
2201 }
2202 
2204 {
2205  DEBTRACE("SubjectElementaryNode::removePort " << port->getName());
2206  if (SubjectInputPort* inp = dynamic_cast<SubjectInputPort*>(port))
2207  {
2208  DEBTRACE("-");
2209  _listSubjectInputPort.remove(inp);
2210  }
2211  else if(SubjectOutputPort* outp = dynamic_cast<SubjectOutputPort*>(port))
2212  {
2213  DEBTRACE("--");
2214  _listSubjectOutputPort.remove(outp);
2215  }
2216  if (SubjectInputDataStreamPort* idsp = dynamic_cast<SubjectInputDataStreamPort*>(port))
2217  {
2218  DEBTRACE("---");
2219  _listSubjectIDSPort.remove(idsp);
2220  }
2221  else if(SubjectOutputDataStreamPort* odsp = dynamic_cast<SubjectOutputDataStreamPort*>(port))
2222  {
2223  DEBTRACE("----");
2224  _listSubjectODSPort.remove(odsp);
2225  }
2226 }
2227 
2229 {
2230  list<InputPort*> listInputPorts = _elementaryNode->getLocalInputPorts();
2231  list<OutputPort*> listOutputPorts = _elementaryNode->getLocalOutputPorts();
2232  list<InputDataStreamPort*> listIDSPorts = _elementaryNode->getSetOfInputDataStreamPort();
2233  list<OutputDataStreamPort*> listODSPorts = _elementaryNode->getSetOfOutputDataStreamPort();
2234  if (SplitterNode *splitterNode = dynamic_cast<SplitterNode*>(_elementaryNode))
2235  listInputPorts.push_back(splitterNode->getFather()->getInputPort("SmplsCollection"));
2236  list<InputPort*>::const_iterator iti;
2237  for (iti = listInputPorts.begin(); iti != listInputPorts.end(); ++iti)
2238  addSubjectInputPort(*iti);
2239  list<OutputPort*>::const_iterator ito;
2240  for (ito = listOutputPorts.begin(); ito != listOutputPorts.end(); ++ito)
2241  addSubjectOutputPort(*ito);
2242  list<InputDataStreamPort*>::const_iterator itids;
2243  for (itids = listIDSPorts.begin(); itids != listIDSPorts.end(); ++itids)
2244  addSubjectIDSPort(*itids);
2245  list<OutputDataStreamPort*>::const_iterator itods;
2246  for (itods = listODSPorts.begin(); itods != listODSPorts.end(); ++itods)
2247  addSubjectODSPort(*itods);
2248 }
2249 
2251 {
2253 }
2254 
2256 {
2258 }
2259 
2260 
2261 // ----------------------------------------------------------------------------
2262 
2263 
2265  : SubjectElementaryNode(inlineNode, parent), _inlineNode(inlineNode)
2266 {
2267 }
2268 
2270 {
2271  DEBTRACE("SubjectInlineNode::~SubjectInlineNode " << getName());
2272 }
2273 
2274 bool SubjectInlineNode::setScript(std::string script)
2275 {
2276  Proc *proc = GuiContext::getCurrent()->getProc();
2277  CommandSetInlineNodeScript *command =
2278  new CommandSetInlineNodeScript(proc->getChildName(_node), script);
2279  if (command->execute())
2280  {
2281  GuiContext::getCurrent()->getInvoc()->add(command);
2282  return true;
2283  }
2284  else delete command;
2285  return false;
2286 }
2287 
2289 {
2290  return _inlineNode->getScript();
2291 }
2292 
2294 {
2295  if (_askRegisterUndo)
2296  {
2297  _askRegisterUndo = false;
2299  }
2300  localclean(command);
2302 }
2303 
2305 {
2306  DEBTRACE("SubjectInlineNode::localClean ");
2307 }
2308 
2309 bool SubjectInlineNode::setExecutionMode(const std::string& mode)
2310 {
2311  DEBTRACE("SubjectInlineNode::setExecutionMode ");
2312  Proc *proc = GuiContext::getCurrent()->getProc();
2313 
2315  if (command->execute())
2316  {
2317  if (!GuiContext::getCurrent()->isLoading()) // do not register command when loading a schema
2318  GuiContext::getCurrent()->getInvoc()->add(command);
2319  else delete command;
2320  return true;
2321  }
2322  else delete command;
2323  return false;
2324 }
2325 
2327 {
2328  DEBTRACE("SubjectInlineNode::setContainer ");
2329  Proc *proc = GuiContext::getCurrent()->getProc();
2330 
2331  CommandSetContainer *command = new CommandSetContainer(proc->getChildName(_node), scont->getName());
2332  if (command->execute())
2333  {
2334  if (!GuiContext::getCurrent()->isLoading()) // do not register command when loading a schema
2335  GuiContext::getCurrent()->getInvoc()->add(command);
2336  else delete command;
2337  return true;
2338  }
2339  else delete command;
2340  return false;
2341 }
2342 
2343 
2344 // ----------------------------------------------------------------------------
2345 
2347  : SubjectElementaryNode(serviceNode, parent), _serviceNode(serviceNode)
2348 {
2349  _subjectReference = 0;
2350  _subRefComponent = 0;
2351 }
2352 
2354 {
2355  DEBTRACE("SubjectServiceNode::~SubjectServiceNode " << getName());
2357  if (!instance) return;
2358  if (GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
2359  {
2361  if (!scomp->hasServices())
2363  }
2364 }
2365 
2367 {
2368  if (_askRegisterUndo)
2369  {
2370  _askRegisterUndo = false;
2372  }
2373  localclean(command);
2375 }
2376 
2378 {
2379  DEBTRACE("SubjectServiceNode::localClean ");
2380  if (_subRefComponent)
2381  {
2382  SubjectComponent *scomp = dynamic_cast<SubjectComponent*>(_subRefComponent->getParent());
2383  if (scomp)
2384  scomp->removeSubServiceFromSet(this);
2385  }
2386  if (_subjectReference)
2387  {
2388 // update( REMOVE, REFERENCE, _subjectReference );
2390  _subjectReference = 0;
2391  }
2392  if (_subRefComponent)
2393  {
2395  _subRefComponent = 0;
2396  }
2397 }
2398 
2399 
2405  std::string compo,
2406  std::string service)
2407 {
2408  DEBTRACE("SubjectServiceNode::setComponentFromCatalog " << compo);
2409 
2410  Proc* proc = GuiContext::getCurrent()->getProc();
2411  string position = proc->getChildName(_node);
2413  new CommandAddComponentFromCatalog(catalog,
2414  position,
2415  compo,
2416  service);
2417  if (command->execute())
2418  GuiContext::getCurrent()->getInvoc()->add(command);
2419  else delete command;
2420  return;
2421 }
2422 
2428 {
2429  DEBTRACE("SubjectServiceNode::setComponent");
2431  if (instance)
2432  {
2433  Proc* proc = GuiContext::getCurrent()->getProc();
2434  string compo = instance->getCompoName();
2435  SubjectComponent* subCompo = 0;
2436  if (! GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
2437  {
2438  DEBTRACE("SubjectServiceNode::setComponent : create subject for compo = " << compo.c_str());
2439  if(proc->componentInstanceMap.count(instance->getInstanceName())==0)
2440  {
2441  std::cerr << "PROBLEM : ComponentInstance should be registered in proc, add it " << instance->getInstanceName() << std::endl;
2442  proc->componentInstanceMap[instance->getInstanceName()] = instance;
2443  Container* cont=instance->getContainer();
2444  //check if the associated container is consistent with containerMap
2445  if(cont)
2446  if (proc->containerMap.count(cont->getName()) == 0)
2447  {
2448  //container exists but is not in containerMap. Clone it, it's probably the result of copy paste from outside the proc
2449  Container* newcont(cont->cloneAlways());
2450  proc->containerMap[cont->getName()]=newcont;
2451  instance->setContainer(newcont);
2452  GuiContext::getCurrent()->getSubjectProc()->addSubjectContainer(newcont, newcont->getName());
2453  }
2454  else
2455  {
2456  if(cont != proc->containerMap[cont->getName()])
2457  {
2458  //the associated container is not the same as the one in containerMap: use the containerMap one
2459  instance->setContainer(proc->containerMap[cont->getName()]);
2460  }
2461  }
2462  }
2463  subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
2464  }
2465  else
2466  {
2467  DEBTRACE("SubjectServiceNode::setComponent : get already created subject for compo = " <<compo.c_str());
2468  subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
2469  }
2470  YASSERT(subCompo);
2471  addSubjectReference(subCompo);
2472  if (_subRefComponent)
2473  subCompo->moveService(_subRefComponent);
2474  else
2475  _subRefComponent = subCompo->attachService(this);
2476  }
2477 }
2478 
2480 {
2481  DEBTRACE("SubjectServiceNode::associateToComponent " << getName() << " " << subcomp->getName());
2482  SubjectReference* oldSReference = _subjectReference;
2485  new CommandAssociateServiceToComponent(aName, subcomp->getName());
2486  if (command->execute())
2487  {
2488  GuiContext::getCurrent()->getInvoc()->add(command);
2489  return true;
2490  }
2491  else delete command;
2492  return false;
2493 }
2494 
2496 {
2497  DEBTRACE("Subject::addSubjectReference " << getName() << " " << ref->getName());
2498  SubjectReference *son = new SubjectReference(ref, this);
2499  _subjectReference = son;
2500  update(ADDREF, 0, son);
2501 }
2502 
2504 {
2505  return _subjectReference;
2506 }
2507 
2508 // ----------------------------------------------------------------------------
2509 
2511  : SubjectInlineNode(pythonNode, parent), _pythonNode(pythonNode)
2512 {
2513 }
2514 
2516 {
2517  DEBTRACE("SubjectPythonNode::~SubjectPythonNode " << getName());
2518 }
2519 
2521 {
2522  if (_askRegisterUndo)
2523  {
2524  _askRegisterUndo = false;
2526  }
2527  localclean(command);
2528  SubjectInlineNode::clean(command);
2529 }
2530 
2532 {
2533  DEBTRACE("SubjectPythonNode::localClean ");
2534 }
2535 
2536 
2537 // ----------------------------------------------------------------------------
2538 
2540  : SubjectInlineNode(pyFuncNode, parent), _pyFuncNode(pyFuncNode)
2541 {
2542 }
2543 
2545 {
2546  DEBTRACE("SubjectPyFuncNode::~SubjectPyFuncNode " << getName());
2547 }
2548 
2549 bool SubjectPyFuncNode::setFunctionName(std::string funcName)
2550 {
2551  Proc *proc = GuiContext::getCurrent()->getProc();
2553  new CommandSetFuncNodeFunctionName(proc->getChildName(_node), funcName);
2554  if (command->execute())
2555  {
2556  GuiContext::getCurrent()->getInvoc()->add(command);
2557  return true;
2558  }
2559  else delete command;
2560  return false;
2561 }
2562 
2564 {
2565  if (_askRegisterUndo)
2566  {
2567  _askRegisterUndo = false;
2569  }
2570  localclean(command);
2571  SubjectInlineNode::clean(command);
2572 }
2573 
2575 {
2576  DEBTRACE("SubjectPyFuncNode::localClean ");
2577 }
2578 
2579 // ----------------------------------------------------------------------------
2580 
2582  : SubjectServiceNode(corbaNode, parent), _corbaNode(corbaNode)
2583 {
2584 }
2585 
2587 {
2588  DEBTRACE("SubjectCORBANode::~SubjectCORBANode " << getName());
2589 }
2590 
2592 {
2593  if (_askRegisterUndo)
2594  {
2595  _askRegisterUndo = false;
2597  }
2598  localclean(command);
2599  SubjectServiceNode::clean(command);
2600 }
2601 
2603 {
2604  DEBTRACE("SubjectCORBANode::localClean ");
2605 }
2606 
2607 
2608 // ----------------------------------------------------------------------------
2609 
2611  : SubjectServiceNode(cppNode, parent), _cppNode(cppNode)
2612 {
2613 }
2614 
2616 {
2617  DEBTRACE("SubjectCppNode::~SubjectCppNode " << getName());
2618 }
2619 
2621 {
2622  if (_askRegisterUndo)
2623  {
2624  _askRegisterUndo = false;
2626  }
2627  localclean(command);
2628  SubjectServiceNode::clean(command);
2629 }
2630 
2632 {
2633  DEBTRACE("SubjectCppNode::localClean ");
2634 }
2635 
2636 
2637 // ----------------------------------------------------------------------------
2638 
2640  : SubjectServiceNode(salomeNode, parent), _salomeNode(salomeNode)
2641 {
2642 }
2643 
2645 {
2646  DEBTRACE("SubjectSalomeNode::~SubjectSalomeNode " << getName());
2647 }
2648 
2650 {
2651  if (_askRegisterUndo)
2652  {
2653  _askRegisterUndo = false;
2655  }
2656  localclean(command);
2657  SubjectServiceNode::clean(command);
2658 }
2659 
2661 {
2662  DEBTRACE("SubjectSalomeNode::localClean ");
2663 }
2664 
2665 
2666 // ----------------------------------------------------------------------------
2667 
2669  Subject *parent)
2670  : SubjectServiceNode(salomePythonNode, parent), _salomePythonNode(salomePythonNode)
2671 {
2672 }
2673 
2675 {
2676  DEBTRACE("SubjectSalomePythonNode::~SubjectSalomePythonNode " << getName());
2677 }
2678 
2680 {
2681  if (_askRegisterUndo)
2682  {
2683  _askRegisterUndo = false;
2685  }
2686  localclean(command);
2687  SubjectServiceNode::clean(command);
2688 }
2689 
2691 {
2692  DEBTRACE("SubjectSalomePythonNode::localClean ");
2693 }
2694 
2695 
2696 // ----------------------------------------------------------------------------
2697 
2699  : SubjectServiceNode(xmlNode, parent), _xmlNode(xmlNode)
2700 {
2701 }
2702 
2704 {
2705  DEBTRACE("SubjectXmlNode::~SubjectXmlNode " << getName());
2706 }
2707 
2709 {
2710  if (_askRegisterUndo)
2711  {
2712  _askRegisterUndo = false;
2714  }
2715  localclean(command);
2716  SubjectServiceNode::clean(command);
2717 }
2718 
2720 {
2721  DEBTRACE("SubjectXmlNode::localClean ");
2722 }
2723 
2724 
2725 // ----------------------------------------------------------------------------
2726 
2728  : SubjectElementaryNode(splitterNode, parent), _splitterNode(splitterNode)
2729 {
2730  _destructible = false;
2731 }
2732 
2734 {
2735  DEBTRACE("SubjectSplitterNode::~SubjectSplitterNode " << getName());
2736 }
2737 
2739 {
2740  if (_askRegisterUndo)
2741  {
2742  _askRegisterUndo = false;
2744  }
2745  localclean(command);
2747 }
2748 
2750 {
2751  DEBTRACE("SubjectSplitterNode::localClean ");
2752 }
2753 
2754 
2756 {
2757  return "splitter";
2758 }
2759 
2760 // ----------------------------------------------------------------------------
2761 
2763  : SubjectElementaryNode(dataNode, parent), _dataNode(dataNode)
2764 {
2765  _destructible = true;
2766 }
2767 
2769 {
2770  DEBTRACE("SubjectDataNode::~SubjectDataNode " << getName());
2771 }
2772 
2774 {
2775  if (_askRegisterUndo)
2776  {
2777  _askRegisterUndo = false;
2779  }
2780  localclean(command);
2782 }
2783 
2785 {
2786  DEBTRACE("SubjectDataNode::localClean ");
2787 }
2788 
2789 // ----------------------------------------------------------------------------
2790 
2792  : SubjectDataNode(presetNode, parent), _presetNode(presetNode)
2793 {
2794  _destructible = true;
2795 }
2796 
2798 {
2799  DEBTRACE("SubjectPresetNode::~SubjectPresetNode " << getName());
2800 }
2801 
2803 {
2804  if (_askRegisterUndo)
2805  {
2806  _askRegisterUndo = false;
2808  }
2809  localclean(command);
2810  SubjectDataNode::clean(command);
2811 }
2812 
2814 {
2815  DEBTRACE("SubjectPresetNode::localClean ");
2816 }
2817 
2818 // ----------------------------------------------------------------------------
2819 
2821  : SubjectDataNode(outNode, parent), _outNode(outNode)
2822 {
2823  _destructible = true;
2824 }
2825 
2827 {
2828  DEBTRACE("SubjectOutNode::~SubjectOutNode " << getName());
2829 }
2830 
2832 {
2833  if (_askRegisterUndo)
2834  {
2835  _askRegisterUndo = false;
2837  }
2838  localclean(command);
2839  SubjectDataNode::clean(command);
2840 }
2841 
2843 {
2844  DEBTRACE("SubjectOutNode::localClean ");
2845 }
2846 
2847 // ----------------------------------------------------------------------------
2848 
2850  : SubjectDataNode(studyInNode, parent), _studyInNode(studyInNode)
2851 {
2852  _destructible = true;
2853 }
2854 
2856 {
2857  DEBTRACE("SubjectStudyInNode::~SubjectStudyInNode " << getName());
2858 }
2859 
2861 {
2862  if (_askRegisterUndo)
2863  {
2864  _askRegisterUndo = false;
2866  }
2867  localclean(command);
2868  SubjectDataNode::clean(command);
2869 }
2870 
2872 {
2873  DEBTRACE("SubjectStudyInNode::localClean ");
2874 }
2875 
2876 // ----------------------------------------------------------------------------
2877 
2879  : SubjectDataNode(studyOutNode, parent), _studyOutNode(studyOutNode)
2880 {
2881  _destructible = true;
2882 }
2883 
2885 {
2886  DEBTRACE("SubjectStudyOutNode::~SubjectStudyOutNode " << getName());
2887 }
2888 
2890 {
2891  if (_askRegisterUndo)
2892  {
2893  _askRegisterUndo = false;
2895  }
2896  localclean(command);
2897  SubjectDataNode::clean(command);
2898 }
2899 
2901 {
2902  DEBTRACE("SubjectStudyOutNode::localClean ");
2903 }
2904 
2905 // ----------------------------------------------------------------------------
2906 
2908  : SubjectComposedNode(forLoop, parent), _forLoop(forLoop)
2909 {
2910  _body = 0;
2911 }
2912 
2914 {
2915  DEBTRACE("SubjectForLoop::~SubjectForLoop " << getName());
2916 }
2917 
2919 {
2920  if (_askRegisterUndo)
2921  {
2922  _askRegisterUndo = false;
2924  }
2925  localclean(command);
2926  SubjectComposedNode::clean(command);
2927 }
2928 
2930 {
2931  DEBTRACE("SubjectForLoop::localClean ");
2932  if (_body)
2933  erase(_body);
2934 }
2935 
2937 {
2938  update(event, type, son);
2939  if (_body)
2940  _body->recursiveUpdate(event, type, son);
2941 }
2942 
2944  std::string compo,
2945  std::string type,
2946  std::string name,
2947  bool newCompoInst)
2948 {
2949  DEBTRACE("SubjectForLoop::addNode("<<catalog<<","<<compo<<","<<type<<","<<name<<")");
2950  SubjectNode* body = 0;
2951  if (_body)
2952  {
2953  GuiContext::getCurrent()->_lastErrorMessage = "If you need several nodes in a loop, put the nodes in a bloc";
2954  return body;
2955  }
2956  body = createNode(catalog, compo, type, name, newCompoInst);
2957  return body;
2958 }
2959 
2961 {
2962  if (isCut)
2963  _body = 0;
2964  else
2965  _body = son;
2966 }
2967 
2969 {
2970  _body = son;
2971 }
2972 
2973 bool SubjectForLoop::setNbSteps(std::string nbSteps)
2974 {
2975  DEBTRACE("SubjectForLoop::setNbSteps " << nbSteps);
2976  Proc *proc = GuiContext::getCurrent()->getProc();
2977  CommandSetForLoopSteps *command =
2978  new CommandSetForLoopSteps(proc->getChildName(getNode()), nbSteps);
2979  if (command->execute())
2980  {
2981  GuiContext::getCurrent()->getInvoc()->add(command);
2982  return true;
2983  }
2984  else delete command;
2985  return false;
2986 }
2988 {
2989  return true;
2990 }
2991 
2993 {
2995 }
2996 
2997 // ----------------------------------------------------------------------------
2998 
3000  : SubjectComposedNode(whileLoop, parent), _whileLoop(whileLoop)
3001 {
3002  _body = 0;
3003 }
3004 
3006 {
3007  DEBTRACE("SubjectWhileLoop::~SubjectWhileLoop " << getName());
3008 }
3009 
3011 {
3012  if (_askRegisterUndo)
3013  {
3014  _askRegisterUndo = false;
3016  }
3017  localclean(command);
3018  SubjectComposedNode::clean(command);
3019 }
3020 
3022 {
3023  DEBTRACE("SubjectWhileLoop::localClean ");
3024  if (_body)
3025  erase(_body);
3026 }
3027 
3029 {
3030  update(event, type, son);
3031  if (_body)
3032  _body->recursiveUpdate(event, type, son);
3033 }
3034 
3036  std::string compo,
3037  std::string type,
3038  std::string name,
3039  bool newCompoInst)
3040 {
3041  DEBTRACE("SubjectWhileLoop::addNode(catalog, compo, type, name)");
3042  SubjectNode* body = 0;
3043  if (_body)
3044  {
3045  GuiContext::getCurrent()->_lastErrorMessage = "If you need several nodes in a loop, put the nodes in a bloc";
3046  return body;
3047  }
3048  body = createNode(catalog, compo, type, name, newCompoInst);
3049  return body;
3050 }
3051 
3053 {
3054  if (isCut)
3055  _body = 0;
3056  else
3057  _body = son;
3058 }
3059 
3061 {
3062  _body = son;
3063 }
3064 
3065 bool SubjectWhileLoop::setCondition(std::string condition)
3066 {
3067  DEBTRACE("SubjectWhileLoop::setCondition " << condition);
3068  Proc *proc = GuiContext::getCurrent()->getProc();
3069  CommandSetWhileCondition *command =
3070  new CommandSetWhileCondition(proc->getChildName(getNode()), condition);
3071  if (command->execute())
3072  {
3073  GuiContext::getCurrent()->getInvoc()->add(command);
3074  return true;
3075  }
3076  else delete command;
3077  return false;
3078 }
3079 
3081 {
3082  return true;
3083 }
3084 
3086 {
3088 }
3089 
3090 // ----------------------------------------------------------------------------
3091 
3093  : SubjectComposedNode(aSwitch, parent), _switch(aSwitch)
3094 {
3095  _bodyMap.clear();
3096 }
3097 
3099 {
3100  DEBTRACE("SubjectSwitch::~SubjectSwitch " << getName());
3101 }
3102 
3104 {
3105  if (_askRegisterUndo)
3106  {
3107  _askRegisterUndo = false;
3109  }
3110  localclean(command);
3111  SubjectComposedNode::clean(command);
3112 }
3113 
3115 {
3116  DEBTRACE("SubjectSwitch::localClean ");
3117  map<int, SubjectNode*>::iterator it;
3118  map<int, SubjectNode*> bodyMapCpy = _bodyMap;
3119  for (it = bodyMapCpy.begin(); it != bodyMapCpy.end(); ++it)
3120  erase((*it).second);
3121 }
3122 
3124 {
3125  update(event, type, son);
3126  map<int, SubjectNode*>::iterator it = _bodyMap.begin();
3127  for (; it != _bodyMap.end(); ++it)
3128  (*it).second->recursiveUpdate(event, type, son);
3129 }
3130 
3132  std::string compo,
3133  std::string type,
3134  std::string name,
3135  bool newCompoInst,
3136  int swCase,
3137  bool replace)
3138 {
3139  DEBTRACE("SubjectSwitch::addNode("<<catalog<<","<<compo<<","<<type<<","<<name<<","<<swCase<<","<<(int)replace<<")");
3140  SubjectNode* body = 0;
3141  if (!replace && _bodyMap.count(swCase))
3142  {
3143  GuiContext::getCurrent()->_lastErrorMessage = "If you need several nodes in a switch case, put the nodes in a bloc";
3144  return body;
3145  }
3146  body = createNode(catalog, compo, type, name, newCompoInst, swCase);
3147  return body;
3148 }
3149 
3151 {
3152  DEBTRACE("SubjectSwitch::removeNode("<<son->getName()<<")");
3153  if (son)
3154  {
3155  int id;
3156  bool isFound = false;
3157  map<int, SubjectNode*>::const_iterator it;
3158  for (it = _bodyMap.begin(); it != _bodyMap.end(); ++it)
3159  {
3160  if ( (*it).second == son )
3161  {
3162  isFound = true;
3163  id = (*it).first;
3164  break;
3165  }
3166  }
3167  if (isFound)
3168  {
3169  DEBTRACE("id = "<<id);
3170  _bodyMap.erase(id);
3171  }
3172  }
3173 }
3174 
3175 std::map<int, SubjectNode*> SubjectSwitch::getBodyMap()
3176 {
3177  return _bodyMap;
3178 }
3179 
3181 {
3182  DEBTRACE("SubjectSwitch::houseKeepingAfterCutPaste");
3183  if (isCut)
3184  _bodyMap.erase(_switch->getRankOfNode(son->getNode()));
3185  else
3186  _bodyMap[_switch->getRankOfNode(son->getNode())] = son;
3187 }
3188 
3189 
3191 {
3192  DEBTRACE("SubjectSwitch::completeChildrenSubjectList");
3193  _bodyMap[_switch->getRankOfNode(son->getNode())] = son;
3194 }
3195 
3197 {
3198  SubjectNode* aChild = 0;
3199 
3200  if (node)
3201  {
3202  map<int, SubjectNode*>::const_iterator it;
3203  for (it = _bodyMap.begin(); it != _bodyMap.end(); ++it)
3204  if ( (*it).second->getNode() == node )
3205  {
3206  aChild = (*it).second;
3207  break;
3208  }
3209  }
3210 
3211  return aChild;
3212 }
3213 
3214 bool SubjectSwitch::setSelect(std::string select)
3215 {
3216  DEBTRACE("SubjectSwitch::setSelect " << select);
3217  Proc *proc = GuiContext::getCurrent()->getProc();
3218  CommandSetSwitchSelect *command =
3220  if (command->execute())
3221  {
3222  GuiContext::getCurrent()->getInvoc()->add(command);
3223  return true;
3224  }
3225  else delete command;
3226  return false;
3227 }
3228 
3229 bool SubjectSwitch::setCase(std::string caseId, SubjectNode* snode)
3230 {
3231  DEBTRACE("SubjectSwitch::setCase " << caseId);
3232  Proc *proc = GuiContext::getCurrent()->getProc();
3233 
3234  Switch* aSwitch = dynamic_cast<Switch*>(getNode());
3235  Node* node =snode->getNode();
3236  int previousRank = aSwitch->getRankOfNode(node);
3237  int newRank = atoi(caseId.c_str());
3238  if (previousRank == newRank) return true; // nothing to do.
3239 
3240  CommandSetSwitchCase *command =
3242  proc->getChildName(snode->getNode()),
3243  caseId);
3244  if (command->execute())
3245  {
3246  GuiContext::getCurrent()->getInvoc()->add(command);
3247  return true;
3248  }
3249  else delete command;
3250  return false;
3251 }
3252 
3254 {
3255  return true;
3256 }
3257 
3259 {
3260  return _switch->edGetConditionPort()->getAsString();
3261 }
3262 
3263 // ----------------------------------------------------------------------------
3264 
3266  : SubjectComposedNode(dynParaLoop, parent), _dynParaLoop(dynParaLoop)
3267 {
3268  _subjectExecNode = NULL;
3269  _subjectInitNode = NULL;
3270  _subjectFinalizeNode = NULL;
3271 }
3272 
3274 {
3275  DEBTRACE("SubjectDynParaLoop::~SubjectDynParaLoop " << getName());
3276 }
3277 
3279 {
3280  update(event, type, son);
3281  if (_subjectExecNode)
3282  _subjectExecNode->recursiveUpdate(event, type, son);
3283  if (_subjectInitNode)
3284  _subjectInitNode->recursiveUpdate(event, type, son);
3286  _subjectFinalizeNode->recursiveUpdate(event, type, son);
3287 }
3288 
3290  std::string compo,
3291  std::string type,
3292  std::string name,
3293  bool newCompoInst)
3294 {
3295  DEBTRACE("SubjectDynParaLoop::addNode(catalog, compo, type, name)");
3296  if (_subjectExecNode)
3297  {
3298  GuiContext::getCurrent()->_lastErrorMessage = "If you need several nodes in a loop, "
3299  "put the nodes in a bloc";
3300  return NULL;
3301  }
3302  return createNode(catalog, compo, type, name, newCompoInst);
3303 }
3304 
3306 {
3307  if (isCut)
3308  removeNode(son);
3309  else
3310  _subjectExecNode = son;
3311 }
3312 
3314 {
3315  if (_askRegisterUndo)
3316  {
3317  _askRegisterUndo = false;
3319  }
3320  localclean(command);
3321  SubjectComposedNode::clean(command);
3322 }
3323 
3325 {
3326  DEBTRACE("SubjectDynParaLoop::localClean ");
3327  if (_subjectExecNode)
3328  {
3331  }
3332  if (_subjectInitNode)
3333  {
3336  }
3338  {
3341  }
3342 }
3343 
3345 {
3346  YASSERT(son);
3347  if (son->getNode() == _dynParaLoop->getExecNode())
3348  _subjectExecNode = son;
3349  else if (son->getNode() == _dynParaLoop->getInitNode())
3350  _subjectInitNode = son;
3351  else if (son->getNode() == _dynParaLoop->getFinalizeNode())
3352  _subjectFinalizeNode = son;
3353  else
3354  YASSERT(false);
3355 }
3356 
3358 {
3359  YASSERT(child);
3360  if (child == _subjectExecNode)
3361  _subjectExecNode = NULL;
3362  else if (child == _subjectInitNode)
3363  _subjectInitNode = NULL;
3364  else if (child == _subjectFinalizeNode)
3365  _subjectFinalizeNode = NULL;
3366  else
3367  YASSERT(false);
3368 }
3369 
3371 {
3372  return _subjectExecNode;
3373 }
3374 
3375 bool SubjectDynParaLoop::setNbBranches(std::string nbBranches)
3376 {
3377  DEBTRACE("SubjectDynParaLoop::setNbBranches " << nbBranches);
3378  Proc * proc = GuiContext::getCurrent()->getProc();
3379  CommandSetForEachBranch * command =
3380  new CommandSetForEachBranch(proc->getChildName(getNode()), nbBranches);
3381  if (command->execute())
3382  {
3383  GuiContext::getCurrent()->getInvoc()->add(command);
3384  return true;
3385  }
3386  else delete command;
3387  return false;
3388 }
3389 
3391 {
3392  return true;
3393 }
3394 
3396 {
3398 }
3399 
3400 // ----------------------------------------------------------------------------
3401 
3403  : SubjectDynParaLoop(forEachLoop, parent), _forEachLoop(forEachLoop)
3404 {
3405  _splitter = 0;
3406 }
3407 
3409 {
3410  DEBTRACE("SubjectForEachLoop::~SubjectForEachLoop " << getName());
3411 }
3412 
3414 {
3415  if (_askRegisterUndo)
3416  {
3417  _askRegisterUndo = false;
3419  }
3420  Node* aSplitterEngine = 0;
3421  if (_splitter) aSplitterEngine = _splitter->getNode();
3422 
3423  localclean(command);
3424  SubjectDynParaLoop::clean(command);
3425 
3426  if (_forEachLoop && aSplitterEngine)
3427  {
3428  DEBTRACE("SubjectForEachLoop::clean: remove for each loop splitter");
3429  _forEachLoop->edRemoveChild(aSplitterEngine);
3430  }
3431 }
3432 
3434 {
3435  DEBTRACE("SubjectForEachLoop::localClean ");
3436  if (_splitter)
3437  {
3439  erase(_splitter);
3440  }
3441 }
3442 
3444 {
3445  if (son && son->getName() == ForEachLoop::NAME_OF_SPLITTERNODE)
3446  _splitter = son;
3447  else
3449 }
3450 
3452 {
3453  YASSERT(child);
3454  if (child->getName() == ForEachLoop::NAME_OF_SPLITTERNODE)
3455  _splitter = NULL;
3456  else {
3458  }
3459 }
3460 
3461 // ----------------------------------------------------------------------------
3462 
3464  Subject *parent)
3465  : SubjectDynParaLoop(optimizerLoop, parent), _optimizerLoop(optimizerLoop)
3466 {
3467 }
3468 
3470 {
3471  DEBTRACE("SubjectOptimizerLoop::~SubjectOptimizerLoop " << getName());
3472 }
3473 
3475 {
3476  if (_askRegisterUndo)
3477  {
3478  _askRegisterUndo = false;
3480  }
3481  localclean(command);
3482  SubjectDynParaLoop::clean(command);
3483 }
3484 
3486 {
3487  DEBTRACE("SubjectOptimizerLoop::localClean ");
3488 }
3489 
3490 bool SubjectOptimizerLoop::setAlgorithm(const std::string& alglib,const std::string& symbol)
3491 {
3492  DEBTRACE("SubjectOptimizerLoop::setAlgorithm " << alglib << " " << symbol);
3493  Proc *proc = GuiContext::getCurrent()->getProc();
3494  CommandSetAlgo *command = new CommandSetAlgo(proc->getChildName(getNode()), alglib, symbol);
3495  if (command->execute())
3496  {
3497  GuiContext::getCurrent()->getInvoc()->add(command);
3498  return true;
3499  }
3500  else delete command;
3501  return false;
3502 }
3503 
3504 // ----------------------------------------------------------------------------
3505 
3507  : Subject(parent), _dataPort(port)
3508 {
3509  _listSubjectLink.clear();
3510  _execValue = "";
3511 }
3512 
3514 {
3515  DEBTRACE("SubjectDataPort::~SubjectDataPort " << getName());
3516  if (isDestructible())
3517  {
3518  Node* node = _dataPort->getNode();
3519  YASSERT(node);
3520  ElementaryNode * father = dynamic_cast<ElementaryNode*>(node);
3521  if (father)
3522  {
3523  DEBTRACE("father->edRemovePort(_dataPort)");
3524  try
3525  {
3526  father->edRemovePort(_dataPort);
3527  }
3528  catch (YACS::Exception &e)
3529  {
3530  DEBTRACE("------------------------------------------------------------------------------");
3531  DEBTRACE("SubjectDataPort::~SubjectDataPort: father->edRemovePort: YACS exception " << e.what());
3532  DEBTRACE("------------------------------------------------------------------------------");
3533  }
3534  }
3535  }
3536 }
3537 
3539 {
3540  if (_askRegisterUndo)
3541  {
3542  _askRegisterUndo = false;
3544  }
3545  localclean(command);
3546  Subject::clean(command);
3547 }
3548 
3550 {
3551  DEBTRACE("SubjectDataPort::localClean ");
3552  list<SubjectLink*> lsl = getListOfSubjectLink();
3553  for (list<SubjectLink*>::iterator it = lsl.begin(); it != lsl.end(); ++it)
3554  erase(*it);
3555 }
3556 
3558 {
3559  return _dataPort->getName();
3560 }
3561 
3562 bool SubjectDataPort::setName(std::string name)
3563 {
3564  DEBTRACE("SubjectDataPort::setName " << name);
3565  Proc *proc = GuiContext::getCurrent()->getProc();
3566  string position = "";
3567  Node *node = getPort()->getNode();
3568  if (proc != dynamic_cast<Proc*>(node))
3569  position = proc->getChildName(node);
3570  else
3571  position = node->getName();
3572 
3573  Command *command = 0;
3574  bool isIn = dynamic_cast<InPort*>(_dataPort);
3575  if (isIn)
3576  command = new CommandRenameInDataPort(position, _dataPort->getName(),name, getType());
3577  else
3578  command = new CommandRenameOutDataPort(position, _dataPort->getName(),name, getType());
3579 
3580  if (command->execute())
3581  {
3582  GuiContext::getCurrent()->getInvoc()->add(command);
3583  return true;
3584  }
3585  else delete command;
3586  return false;
3587 }
3588 
3590 {
3591  return _dataPort;
3592 }
3593 
3594 bool SubjectDataPort::tryCreateLink(SubjectDataPort *subOutport, SubjectDataPort *subInport,bool control)
3595 {
3596  DEBTRACE("SubjectDataPort::tryCreateLink");
3597 
3598  InPort *inp = dynamic_cast<InPort*>(subInport->getPort());
3599  OutPort *outp = dynamic_cast<OutPort*>(subOutport->getPort());
3600  if (outp && outp->isAlreadyLinkedWith(inp))
3601  {
3602  DEBTRACE("isAlreadyLinkedWith");
3603  GuiContext::getCurrent()->_lastErrorMessage = "Ports are already linked";
3604  return false;
3605  }
3606 
3607  Proc *proc = GuiContext::getCurrent()->getProc();
3608 
3609  string outNodePos = "";
3610  SubjectNode *sno = dynamic_cast<SubjectNode*>(subOutport->getParent());
3611  YASSERT(sno);
3612  Node *outNode = sno->getNode();
3613  outNodePos = proc->getChildName(outNode);
3614  string outportName = subOutport->getName();
3615 
3616  string inNodePos = "";
3617  SubjectNode *sni = dynamic_cast<SubjectNode*>(subInport->getParent());
3618  YASSERT(sni);
3619  Node *inNode = sni->getNode();
3620  inNodePos = proc->getChildName(inNode);
3621  string inportName = subInport->getName();
3622 
3623  CommandAddLink *command = new CommandAddLink(outNodePos, outportName, subOutport->getType(),
3624  inNodePos, inportName, subInport->getType(), control);
3625  if (command->execute())
3626  {
3627  GuiContext::getCurrent()->getInvoc()->add(command);
3628  return true;
3629  }
3630  else
3631  {
3632  delete command;
3633  return false;
3634  }
3635 }
3636 
3640 bool SubjectDataPort::setValue(std::string value)
3641 {
3642  return false;
3643 }
3644 
3645 void SubjectDataPort::setExecValue(std::string value)
3646 {
3647  _execValue = value;
3648 }
3649 
3651 {
3652  return _execValue;
3653 }
3654 
3656 {
3657  DEBTRACE("SubjectDataPort::registerUndoDestroy");
3658  Proc *proc = GuiContext::getCurrent()->getProc();
3659  SubjectNode *sno = dynamic_cast<SubjectNode*>(getParent());
3660  YASSERT(sno);
3661  Node *node = sno->getNode();
3662  string nodeName = proc->getChildName(node);
3663  string portName = getName();
3664  ElementaryNode* father = dynamic_cast<ElementaryNode*>(node);
3665  YASSERT(father);
3666 
3667  DataPort *port = getPort();
3668  TypeCode *dtyp = port->edGetType();
3669  string typeName = dtyp->name();
3670  Catalog *undoCata = GuiContext::getCurrent()->getInvoc()->getUndoCata();
3671  undoCata->_typeMap[typeName] = dtyp;
3672 
3673  Command *command = 0;
3674  Command *comm2 =0;
3675  TypeOfElem elemType = getType();
3676  switch (elemType)
3677  {
3678  case INPUTPORT:
3679  command = new CommandAddInputPortFromCatalog(undoCata, typeName, nodeName, portName);
3680  {
3681  int rang = 1;
3682  int nbUp = 0;
3683  list<InputPort*> plist = father->getSetOfInputPort();
3684  list<InputPort*>::iterator pos = plist.begin();
3685  for (; (*pos) != port; pos++)
3686  rang++;
3687  nbUp = plist.size() -rang;
3688  if (nbUp)
3689  comm2 = new CommandOrderInputPorts(nodeName, portName, nbUp);
3690  }
3691  break;
3692  case OUTPUTPORT:
3693  command = new CommandAddOutputPortFromCatalog(undoCata, typeName, nodeName, portName);
3694  {
3695  int rang = 1;
3696  int nbUp = 0;
3697  list<OutputPort*> plist = father->getSetOfOutputPort();
3698  list<OutputPort*>::iterator pos = plist.begin();
3699  for (; (*pos) != port; pos++)
3700  rang++;
3701  nbUp = plist.size() -rang;
3702  if (nbUp)
3703  comm2 = new CommandOrderOutputPorts(nodeName, portName, nbUp);
3704  }
3705  break;
3706  case INPUTDATASTREAMPORT:
3707  command = new CommandAddIDSPortFromCatalog(undoCata, typeName, nodeName, portName);
3708  break;
3709  case OUTPUTDATASTREAMPORT:
3710  command = new CommandAddODSPortFromCatalog(undoCata, typeName, nodeName, portName);
3711  break;
3712  }
3713  if (command)
3714  GuiContext::getCurrent()->getInvoc()->add(command);
3715  if (comm2)
3716  GuiContext::getCurrent()->getInvoc()->add(comm2);
3717  //save links
3718  list<SubjectLink*> lsl = getListOfSubjectLink();
3719  for (list<SubjectLink*>::iterator it = lsl.begin(); it != lsl.end(); ++it)
3720  {
3721  (*it)->registerUndoDestroy();
3722  }
3723 }
3724 
3725 
3726 // ----------------------------------------------------------------------------
3727 
3729  : SubjectDataPort(port, parent), _inputPort(port)
3730 {
3731  Node *node = _inputPort->getNode();
3732  if (ForLoop* forloop = dynamic_cast<ForLoop*>(node))
3733  {
3734  if (_inputPort->getName() == "nsteps") _destructible = false;
3735  }
3736  else if (WhileLoop* whileloop = dynamic_cast<WhileLoop*>(node))
3737  {
3738  if (_inputPort->getName() == "condition") _destructible = false;
3739  }
3740  else if (Switch* aSwitch = dynamic_cast<Switch*>(node))
3741  {
3742  if (_inputPort->getName() == "select") _destructible = false;
3743  }
3744  else if (ForEachLoop* foreach = dynamic_cast<ForEachLoop*>(node))
3745  {
3746  if (_inputPort->getName() == "nbBranches") _destructible = false;
3747  }
3748  else if (OptimizerLoop* optil = dynamic_cast<OptimizerLoop*>(node))
3749  {
3750  if (_inputPort->getName() == "nbBranches") _destructible = false;
3751  }
3752  else if (SplitterNode* split = dynamic_cast<SplitterNode*>(node))
3753  {
3754  if (_inputPort->getName() == "SmplsCollection") _destructible = false;
3755  }
3756 
3757 }
3758 
3760 {
3761  DEBTRACE("SubjectInputPort::~SubjectInputPort " << getName());
3762 }
3763 
3765 {
3766  if (_askRegisterUndo)
3767  {
3768  _askRegisterUndo = false;
3770  }
3771  localclean(command);
3772  SubjectDataPort::clean(command);
3773 }
3774 
3776 {
3777  DEBTRACE("SubjectInputPort::localClean ");
3778  if (_parent)
3779  {
3780  SubjectElementaryNode* elem = dynamic_cast<SubjectElementaryNode*>(_parent);
3781  if (elem) elem->removePort(this);
3782  }
3783 }
3784 
3785 bool SubjectInputPort::setValue(std::string value)
3786 {
3787  DEBTRACE("SubjectInputPort::setValue " << value);
3788  Proc *proc = GuiContext::getCurrent()->getProc();
3789  CommandSetInPortValue *command =
3790  new CommandSetInPortValue(proc->getChildName(getPort()->getNode()), getName(), value);
3791  if (command->execute())
3792  {
3793  GuiContext::getCurrent()->getInvoc()->add(command);
3794  return true;
3795  }
3796  else delete command;
3797  return false;
3798 }
3799 
3800 // ----------------------------------------------------------------------------
3801 
3803  : SubjectDataPort(port, parent), _outputPort(port)
3804 {
3805  if (DynParaLoop* dynloop = dynamic_cast<DynParaLoop*>(_outputPort->getNode()))
3806  {
3807  if (_outputPort == dynloop->edGetSamplePort()) _destructible = false;
3808  }
3809 }
3810 
3812 {
3813  DEBTRACE("SubjectOutputPort::~SubjectOutputPort " << getName());
3814 }
3815 
3817 {
3818  if (_askRegisterUndo)
3819  {
3820  _askRegisterUndo = false;
3822  }
3823  localclean(command);
3824  SubjectDataPort::clean(command);
3825 }
3826 
3828 {
3829  DEBTRACE("SubjectOutputPort::localClean ");
3830  if (_parent)
3831  {
3832  SubjectElementaryNode* elem = dynamic_cast<SubjectElementaryNode*>(_parent);
3833  if (elem) elem->removePort(this);
3834  }
3835 }
3836 
3837 bool SubjectOutputPort::setValue(std::string value)
3838 {
3839  DEBTRACE("SubjectOutputPort::setValue " << value);
3840  Proc *proc = GuiContext::getCurrent()->getProc();
3841  CommandSetOutPortValue *command =
3842  new CommandSetOutPortValue(proc->getChildName(getPort()->getNode()), getName(), value);
3843  if (command->execute())
3844  {
3845  GuiContext::getCurrent()->getInvoc()->add(command);
3846  return true;
3847  }
3848  else delete command;
3849  return false;
3850 }
3851 
3852 // ----------------------------------------------------------------------------
3853 
3855  Subject *parent)
3856  : SubjectDataPort(port, parent), _inputDataStreamPort(port)
3857 {
3858 }
3859 
3861 {
3862  DEBTRACE("SubjectInputDataStreamPort::~SubjectInputDataStreamPort " << getName());
3863 }
3864 
3865 std::map<std::string, std::string> SubjectInputDataStreamPort::getProperties()
3866 {
3868 }
3869 
3871 {
3872  std::vector<std::string> props;
3873  props.push_back("StorageLevel");
3874  //props.push_back("DependencyType");
3875  props.push_back("DateCalSchem");
3876  props.push_back("Alpha");
3877  props.push_back("DeltaT");
3878  props.push_back("InterpolationSchem");
3879  props.push_back("ExtrapolationSchem");
3880  return props;
3881 }
3882 
3883 bool SubjectInputDataStreamPort::setProperties(std::map<std::string, std::string> properties)
3884 {
3885  Proc *proc = GuiContext::getCurrent()->getProc();
3886  CommandSetDSPortProperties *command =
3887  new CommandSetDSPortProperties(proc->getChildName(getPort()->getNode()), getName(), true, properties);
3888  if (command->execute())
3889  {
3890  GuiContext::getCurrent()->getInvoc()->add(command);
3891  return true;
3892  }
3893  else delete command;
3894  return false;
3895 }
3896 
3898 {
3899  if (_askRegisterUndo)
3900  {
3901  _askRegisterUndo = false;
3903  }
3904  localclean(command);
3905  SubjectDataPort::clean(command);
3906 }
3907 
3909 {
3910  DEBTRACE("SubjectInputDataStreamPort::localClean ");
3911 }
3912 
3914 {
3915  DEBTRACE("SubjectInputDataStreamPort::registerUndoDestroy");
3917  map<string,string> properties = getProperties();
3918  if (properties.empty())
3919  return;
3920  Proc *proc = GuiContext::getCurrent()->getProc();
3921  SubjectNode *sno = dynamic_cast<SubjectNode*>(getParent());
3922  YASSERT(sno);
3923  Node *node = sno->getNode();
3924  string nodeName = proc->getChildName(node);
3925  string portName = getName();
3926  Command *command = new CommandSetDSPortProperties(nodeName, portName, true, properties);
3927  GuiContext::getCurrent()->getInvoc()->add(command);
3928 }
3929 
3930 // ----------------------------------------------------------------------------
3931 
3933  Subject *parent)
3934  : SubjectDataPort(port, parent), _outputDataStreamPort(port)
3935 {
3936 }
3937 
3939 {
3940  DEBTRACE("SubjectOutputDataStreamPort::~SubjectOutputDataStreamPort " << getName());
3941 }
3942 
3943 std::map<std::string, std::string> SubjectOutputDataStreamPort::getProperties()
3944 {
3946 }
3947 
3948 bool SubjectOutputDataStreamPort::setProperties(std::map<std::string, std::string> properties)
3949 {
3950  Proc *proc = GuiContext::getCurrent()->getProc();
3951  CommandSetDSPortProperties *command =
3952  new CommandSetDSPortProperties(proc->getChildName(getPort()->getNode()), getName(), false, properties);
3953  if (command->execute())
3954  {
3955  GuiContext::getCurrent()->getInvoc()->add(command);
3956  return true;
3957  }
3958  else delete command;
3959  return false;
3960 }
3961 
3963 {
3964  if (_askRegisterUndo)
3965  {
3966  _askRegisterUndo = false;
3968  }
3969  localclean(command);
3970  SubjectDataPort::clean(command);
3971 }
3972 
3974 {
3975  DEBTRACE("SubjectOutputDataStreamPort::localClean ");
3976 }
3977 
3979 {
3980  DEBTRACE("SubjectOutputDataStreamPort::registerUndoDestroy");
3982  map<string,string> properties = getProperties();
3983  if (properties.empty())
3984  return;
3985  Proc *proc = GuiContext::getCurrent()->getProc();
3986  SubjectNode *sno = dynamic_cast<SubjectNode*>(getParent());
3987  YASSERT(sno);
3988  Node *node = sno->getNode();
3989  string nodeName = proc->getChildName(node);
3990  string portName = getName();
3991  Command *command = new CommandSetDSPortProperties(nodeName, portName, false, properties);
3992  GuiContext::getCurrent()->getInvoc()->add(command);
3993 }
3994 
3995 // ----------------------------------------------------------------------------
3996 
3998  SubjectDataPort* outPort,
3999  SubjectNode* subInNode,
4000  SubjectDataPort* inPort,
4001  Subject *parent)
4002  : Subject(parent),
4003  _subOutNode(subOutNode), _outPort(outPort), _subInNode(subInNode), _inPort(inPort)
4004 {
4005  _name = "";
4006  ComposedNode *cla = ComposedNode::getLowestCommonAncestor(_subOutNode->getNode()->getFather(),
4007  _subInNode->getNode()->getFather());
4008  DEBTRACE(_subOutNode->getName() << "." << _outPort->getName());
4009  DEBTRACE(_subInNode->getName() << "." << _inPort->getName());
4010  DEBTRACE(cla->getName());
4011  _name += cla->getChildName(_subOutNode->getNode());
4012  _name += "." + _outPort->getName();
4013  _name += "->";
4014  _name += cla->getChildName(_subInNode->getNode());
4015  _name += "." + _inPort->getName();
4016  DEBTRACE("SubjectLink::SubjectLink " << _name);
4017 }
4018 
4020 {
4021  DEBTRACE("SubjectLink::~SubjectLink " << getName());
4024 }
4025 
4027 {
4028  if (_askRegisterUndo)
4029  {
4030  _askRegisterUndo = false;
4032  }
4033  localclean(command);
4034  Subject::clean(command);
4035 }
4036 
4038 {
4039  DEBTRACE("SubjectLink::localClean ");
4040  if (_parent)
4041  {
4042  DEBTRACE("clean link: " << _parent->getName() << " " << getName());
4043  SubjectComposedNode* father = dynamic_cast<SubjectComposedNode*>(_parent);
4044  YASSERT(father);
4045  father->removeLink(this); // --- clean subjects first
4046  _cla = dynamic_cast<ComposedNode*>(father->getNode());
4047  YASSERT(_cla);
4048  _outp = dynamic_cast<OutPort*>(_outPort->getPort());
4049  YASSERT(_outp);
4050  _inp = dynamic_cast<InPort*>(_inPort->getPort());
4051  YASSERT(_inp);
4052  if (isDestructible())
4054  }
4055 }
4056 
4058 {
4059  return _name;
4060 }
4061 
4062 std::map<std::string, std::string> SubjectLink::getProperties()
4063 {
4064  return getSubjectInPort()->getProperties();
4065 }
4066 
4067 std::vector<std::string> SubjectLink::knownProperties()
4068 {
4069  return getSubjectInPort()->knownProperties();
4070 }
4071 
4072 bool SubjectLink::setProperties(std::map<std::string, std::string> properties)
4073 {
4074  Proc *proc = GuiContext::getCurrent()->getProc();
4075  CommandSetLinkProperties *command =
4076  new CommandSetLinkProperties(proc->getChildName(getSubjectOutPort()->getPort()->getNode()), getSubjectOutPort()->getName(),
4077  proc->getChildName(getSubjectInPort()->getPort()->getNode()), getSubjectInPort()->getName(),
4078  properties);
4079  if (command->execute())
4080  {
4081  GuiContext::getCurrent()->getInvoc()->add(command);
4082  return true;
4083  }
4084  else delete command;
4085  return false;
4086 }
4087 
4089 {
4090  DEBTRACE("SubjectLink::registerUndoDestroy");
4091  Proc *proc = GuiContext::getCurrent()->getProc();
4092  Node *outn = getSubjectOutNode()->getNode();
4093  Node *inn = getSubjectInNode()->getNode();
4094  DataPort *outp = getSubjectOutPort()->getPort();
4095  DataPort *inp = getSubjectInPort()->getPort();
4096  CommandAddLink *command = new CommandAddLink(proc->getChildName(outn),
4097  outp->getName(),
4099  proc->getChildName(inn),
4100  inp->getName(),
4102  false);
4103  GuiContext::getCurrent()->getInvoc()->add(command);
4104 
4105  map<string, string> properties = getProperties();
4106  if (properties.empty())
4107  return;
4108 
4110  outp->getName(),
4111  proc->getChildName(inn),
4112  inp->getName(),
4113  properties);
4114  GuiContext::getCurrent()->getInvoc()->add(command2);
4115 }
4116 
4117 // ----------------------------------------------------------------------------
4118 
4120  SubjectNode* subInNode,
4121  Subject *parent)
4122  : Subject(parent),
4123  _subOutNode(subOutNode), _subInNode(subInNode)
4124 {
4125  _name = "";
4126  ComposedNode *cla = ComposedNode::getLowestCommonAncestor(_subOutNode->getNode()->getFather(),
4127  _subInNode->getNode()->getFather());
4130  DEBTRACE(cla->getName());
4131  _name += cla->getChildName(_subOutNode->getNode());
4132  _name += "-->>";
4133  _name += cla->getChildName(_subInNode->getNode());
4134  DEBTRACE("SubjectControlLink::SubjectControlLink " << _name);
4135 }
4136 
4138 {
4139  DEBTRACE("SubjectControlLink::~SubjectControlLink " << getName());
4140  if (isDestructible())
4141  {
4142  try
4143  {
4144 
4146  }
4147  catch (YACS::Exception &e)
4148  {
4149  DEBTRACE("------------------------------------------------------------------------------");
4150  DEBTRACE("SubjectControlLink::~SubjectControlLink: edRemoveLink YACS exception " << e.what());
4151  DEBTRACE("------------------------------------------------------------------------------");
4152  }
4153  }
4154 }
4155 
4157 {
4158  if (_askRegisterUndo)
4159  {
4160  _askRegisterUndo = false;
4162  }
4163  localclean(command);
4164  Subject::clean(command);
4165 }
4166 
4168 {
4169  DEBTRACE("SubjectControlLink::localClean ");
4170  if (_parent)
4171  {
4172  DEBTRACE("clean control link: " << _parent->getName() << " " << getName());
4173  SubjectComposedNode* father = dynamic_cast<SubjectComposedNode*>(_parent);
4174  YASSERT(father);
4175  father->removeControlLink(this); // --- clean subjects first
4176  _cla = dynamic_cast<ComposedNode*>(father->getNode());
4177  YASSERT(_cla);
4178  }
4179 }
4180 
4182 {
4183  return _name;
4184 }
4185 
4187 {
4188  DEBTRACE("SubjectControlLink::registerUndoDestroy");
4189  Proc *proc = GuiContext::getCurrent()->getProc();
4190  Node *outn = getSubjectOutNode()->getNode();
4191  Node *inn = getSubjectInNode()->getNode();
4192  CommandAddControlLink *command = new CommandAddControlLink(proc->getChildName(outn),
4193  proc->getChildName(inn));
4194  GuiContext::getCurrent()->getInvoc()->add(command);
4195 }
4196 
4197 // ----------------------------------------------------------------------------
4198 
4200  : Subject(parent), _compoInst(component)
4201 {
4202  _compoInst->incrRef();
4203  _subRefContainer = 0;
4204  _subServiceSet.clear();
4205  _subReferenceMap.clear();
4206 }
4207 
4209 {
4210  Proc* aProc = GuiContext::getCurrent()->getProc();
4211  if ( aProc )
4212  {
4215  }
4216  _compoInst->decrRef();
4217 }
4218 
4220 {
4221  if (_askRegisterUndo)
4222  {
4223  _askRegisterUndo = false;
4225  }
4226  localclean(command);
4227  Subject::clean(command);
4228 }
4229 
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 }
4266 
4268 {
4269  return _compoInst->getInstanceName();
4270 }
4271 
4272 std::pair<std::string, int> SubjectComponent::getKey()
4273 {
4274  std::pair<std::string, int> key = std::pair<std::string, int>(_compoInst->getCompoName(), _compoInst->getNumId());
4275  return key;
4276 }
4277 
4279 {
4280  return _compoInst;
4281 }
4282 
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 }
4307 
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 }
4323 
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 }
4333 
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 }
4345 
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 }
4362 
4364 {
4365  DEBTRACE("SubjectComponent::removeSubServiceFromSet " << getName() << " " << service->getName());
4366  _subServiceSet.erase(service);
4367  _subReferenceMap.erase(service);
4368 }
4369 
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 }
4379 
4380 bool SubjectComponent::setProperties(std::map<std::string, std::string> properties)
4381 {
4383  if (command->execute())
4384  {
4385  GuiContext::getCurrent()->getInvoc()->add(command);
4386  return true;
4387  }
4388  else delete command;
4389  return false;
4390 }
4391 
4392 std::map<std::string, std::string> SubjectComponent::getProperties()
4393 {
4394  return _compoInst->getProperties();
4395 }
4396 
4397 // ----------------------------------------------------------------------------
4398 
4400 {
4401  if(!container)
4402  return 0;
4403  if(!dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container))
4404  return new SubjectContainer(container,parent);
4405  else
4406  return new SubjectHPContainer(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(container),parent);
4407 }
4408 
4409 SubjectContainerBase::SubjectContainerBase(YACS::ENGINE::Container* container, Subject *parent):Subject(parent), _container(container)
4410 {
4411  _subComponentSet.clear();
4412  _subReferenceMap.clear();
4413 }
4414 
4416 {
4417  DEBTRACE("SubjectContainerBase::~SubjectContainerBase");
4418  Proc* aProc = GuiContext::getCurrent()->getProc();
4419  if ( aProc )
4420  {
4421  map<ComponentInstance*,SubjectComponent*> mapOfSubjectComponentCpy
4423  map<ComponentInstance*,SubjectComponent*>::iterator it = mapOfSubjectComponentCpy.begin();
4424  for ( ; it!=mapOfSubjectComponentCpy.end(); it++ )
4425  if ( (*it).first && (*it).first->getContainer() == _container )
4426  {
4427  (*it).first->setContainer(0);
4428  GuiContext::getCurrent()->getSubjectProc()->destroy((*it).second);
4429  }
4430 
4432  aProc->removeContainer(_container);
4433  }
4434 }
4435 
4436 std::map<std::string, std::string> SubjectContainerBase::getProperties()
4437 {
4438  return _container->getProperties();
4439 }
4440 
4441 bool SubjectContainerBase::setProperties(std::map<std::string, std::string> properties)
4442 {
4444  if (command->execute())
4445  {
4446  GuiContext::getCurrent()->getInvoc()->add(command);
4447  return true;
4448  }
4449  else
4450  delete command;
4451  return false;
4452 }
4453 
4454 bool SubjectContainerBase::setName(std::string name)
4455 {
4456  DEBTRACE("SubjectContainer::setName " << name);
4457  if (name == getName())
4458  return true;
4459  CommandRenameContainer* command = new CommandRenameContainer(getName(), name);
4460  if (command->execute())
4461  {
4462  GuiContext::getCurrent()->getInvoc()->add(command);
4463  return true;
4464  }
4465  else delete command;
4466  return false;
4467 }
4468 
4470 {
4471  DEBTRACE("SubjectContainer::attachComponent");
4472  SubjectReference *son = new SubjectReference(component, this);
4473  _subComponentSet.insert(component);
4474  _subReferenceMap[component] = son;
4475  update(ADDCHILDREF, COMPONENT, son);
4476  return son;
4477 }
4478 
4480 {
4481  DEBTRACE("SubjectContainer::detachComponent");
4482  YASSERT(_subReferenceMap.count(component));
4483  SubjectReference *reference = _subReferenceMap[component];
4484  update(REMOVECHILDREF, PYTHONNODE, reference);
4485  _subComponentSet.erase(component);
4486  _subReferenceMap.erase(component);
4487  erase(reference);
4488 }
4489 
4491 {
4492  DEBTRACE("SubjectContainer::moveComponent");
4493  SubjectContainer* oldcont = dynamic_cast<SubjectContainer*>(reference->getParent());
4494  YASSERT(oldcont);
4495  SubjectComponent* component = dynamic_cast<SubjectComponent*>(reference->getReference());
4496  _subComponentSet.insert(component);
4497  _subReferenceMap[component] = reference;
4498  oldcont->removeSubComponentFromSet(component);
4499  oldcont->update(CUT, COMPONENT, reference);
4500  reference->reparent(this);
4501  update(PASTE, COMPONENT, reference);
4502 }
4503 
4505 {
4506  DEBTRACE("SubjectContainer::removeSubComponentFromSet");
4507  _subComponentSet.erase(component);
4508  _subReferenceMap.erase(component);
4509 }
4510 
4512 {
4513  DEBTRACE("SubjectContainer::notifyComponentsChange");
4514  set<SubjectComponent*>::iterator it = _subComponentSet.begin();
4515  for(; it != _subComponentSet.end(); ++it)
4516  {
4517  (*it)->update(event, type, son);
4518  (*it)->notifyServicesChange(event, type, son);
4519  }
4520 }
4521 
4523 {
4524  if (_askRegisterUndo)
4525  {
4526  _askRegisterUndo = false;
4528  }
4529  localclean(command);
4530  Subject::clean(command);
4531 }
4532 
4534 {
4535  DEBTRACE("SubjectContainerBase::localClean ");
4536  Proc* aProc = GuiContext::getCurrent()->getProc();
4537  if ( aProc )
4538  {
4539  SubjectComponent* compo;
4540  map<ComponentInstance*,SubjectComponent*>::iterator it = GuiContext::getCurrent()->_mapOfSubjectComponent.begin();
4541  std::list<SubjectComponent*> compos;
4542  for ( ; it!=GuiContext::getCurrent()->_mapOfSubjectComponent.end(); it++ )
4543  if ( (*it).first && (*it).first->getContainer() == _container )
4544  {
4545  compo=(*it).second;
4546  (*it).first->setContainer(0);
4547  compos.push_back((*it).second);
4548  }
4549  while(!compos.empty())
4550  {
4551  compo=compos.front();
4552  compos.pop_front();
4555  }
4556  }
4557 }
4558 
4560 {
4561  return _container->getName();
4562 }
4563 
4564 // ----------------------------------------------------------------------------
4565 
4567 {
4568 }
4569 
4571 {
4572  DEBTRACE("SubjectContainer::registerUndoDestroy");
4573  Command *command = new CommandAddContainer(getName(),"");
4574  GuiContext::getCurrent()->getInvoc()->add(command);
4575 }
4576 
4577 // ----------------------------------------------------------------------------
4578 
4580 {
4581 }
4582 
4584 {
4585  if(!_container)
4586  return 0;
4587  else
4588  {
4589  YACS::ENGINE::HomogeneousPoolContainer *ret(dynamic_cast<YACS::ENGINE::HomogeneousPoolContainer *>(_container));
4590  if(!ret)
4591  throw Exception("Invalid container type in SubjectHPContainer !");
4592  return ret;
4593  }
4594 }
4595 
4597 {
4598  DEBTRACE("SubjectHPContainer::registerUndoDestroy");
4599  Command *command = new CommandAddHPContainer(getName(),"");
4600  GuiContext::getCurrent()->getInvoc()->add(command);
4601 }
4602 
4603 // ----------------------------------------------------------------------------
4604 
4606  : Subject(parent), _typeCode(typeCode), _alias(alias)
4607 {
4608 }
4609 
4611 {
4612 }
4613 
4615 {
4616  if (_askRegisterUndo)
4617  {
4618  _askRegisterUndo = false;
4620  }
4621  localclean(command);
4622  Subject::clean(command);
4623 }
4624 
4626 {
4627  DEBTRACE("SubjectDataType::localClean ");
4628 }
4629 
4631 {
4632  return _typeCode->name();
4633 }
4634 
4636 {
4637  return _alias;
4638 }
4639 
4641 {
4642  return _typeCode;
4643 }
4644 
4645 // ----------------------------------------------------------------------------