Salome HOME
Copyright update 2021
[modules/yacs.git] / src / hmi / commandsProc.cxx
1 // Copyright (C) 2006-2021  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 "commandsProc.hxx"
22
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 "XMLNode.hxx"
36 #include "ForLoop.hxx"
37 #include "ForEachLoop.hxx"
38 #include "WhileLoop.hxx"
39 #include "Switch.hxx"
40 #include "OptimizerLoop.hxx"
41 #include "PresetNode.hxx"
42 #include "OutNode.hxx"
43 #include "StudyNodes.hxx"
44 #include "Exception.hxx"
45 #include "DataPort.hxx"
46 #include "InputDataStreamPort.hxx"
47 #include "OutputDataStreamPort.hxx"
48 #include "StudyPorts.hxx"
49 #include "PresetPorts.hxx"
50 #include "ComponentDefinition.hxx"
51 #include "SalomeContainer.hxx"
52 #include "SalomeHPContainer.hxx"
53 #include "SalomeComponent.hxx"
54 #include "TypeCode.hxx"
55 #include "RuntimeSALOME.hxx"
56 #include "TypeConversions.hxx"
57
58 #include "guiContext.hxx"
59
60 #include <iostream>
61 #include <sstream>
62 #include <string>
63
64 //#define _DEVDEBUG_
65 #include "YacsTrace.hxx"
66
67 using namespace std;
68
69 using namespace YACS;
70 using namespace YACS::ENGINE;
71 using namespace YACS::HMI;
72
73
74 static std::map<int, std::string> createErrorMsgMap()
75 {
76   std::map<int, std::string> m;
77   m[1] = "\nUse the [Ctrl] Drag_N_Drop method if you want to create a input/output link without the associated control link";
78   return m;
79 }
80
81 std::map<int, std::string> ErrorMsg = createErrorMsgMap();
82
83 void setErrorMsg(YACS::Exception& ex)
84 {
85   DEBTRACE("errorNumber= "<<ex.errNumber);
86   if(ex.errNumber > 0 && ErrorMsg.count(ex.errNumber) != 0)
87     {
88       DEBTRACE(ErrorMsg[ex.errNumber]);
89       GuiContext::getCurrent()->_lastErrorMessage = ex.what() + ErrorMsg[ex.errNumber];
90     }
91   else
92     GuiContext::getCurrent()->_lastErrorMessage = ex.what();
93 }
94
95 std::map<int, std::string> ProcInvoc::_typeNameMap;
96
97 // ----------------------------------------------------------------------------
98
99 ProcInvoc::ProcInvoc()
100   : Invocator()
101 {
102   _typeNameMap.clear();
103   _typeNameMap[SALOMEPROC]           = "SALOMEPROC";
104   _typeNameMap[BLOC]                 = "BLOC";
105   _typeNameMap[FOREACHLOOP]          = "FOREACHLOOP";
106   _typeNameMap[OPTIMIZERLOOP]        = "OPTIMIZERLOOP";
107   _typeNameMap[FORLOOP]              = "FORLOOP";
108   _typeNameMap[WHILELOOP]            = "WHILELOOP";
109   _typeNameMap[SWITCH]               = "SWITCH";
110   _typeNameMap[PYTHONNODE]           = "PYTHONNODE";
111   _typeNameMap[PYFUNCNODE]           = "PYFUNCNODE";
112   _typeNameMap[CORBANODE]            = "CORBANODE";
113   _typeNameMap[SALOMENODE]           = "SALOMENODE";
114   _typeNameMap[CPPNODE]              = "CPPNODE";
115   _typeNameMap[SALOMEPYTHONNODE]     = "SALOMEPYTHONNODE";
116   _typeNameMap[XMLNODE]              = "XMLNODE";
117   _typeNameMap[SPLITTERNODE]         = "SPLITTERNODE";
118   _typeNameMap[DFTODSFORLOOPNODE]    = "DFTODSFORLOOPNODE";
119   _typeNameMap[DSTODFFORLOOPNODE]    = "DSTODFFORLOOPNODE";
120   _typeNameMap[PRESETNODE]           = "PRESETNODE";
121   _typeNameMap[OUTNODE]              = "OUTNODE";
122   _typeNameMap[STUDYINNODE]          = "STUDYINNODE";
123   _typeNameMap[STUDYOUTNODE]         = "STUDYOUTNODE";
124   _typeNameMap[INPUTPORT]            = "INPUTPORT";
125   _typeNameMap[OUTPUTPORT]           = "OUTPUTPORT";
126   _typeNameMap[INPUTDATASTREAMPORT]  = "INPUTDATASTREAMPORT";
127   _typeNameMap[OUTPUTDATASTREAMPORT] = "OUTPUTDATASTREAMPORT";
128   _typeNameMap[DATALINK]             = "DATALINK";
129   _typeNameMap[CONTROLLINK]          = "CONTROLLINK";
130   _typeNameMap[CONTAINER]            = "CONTAINER";
131   _typeNameMap[COMPONENT]            = "COMPONENT";
132   _typeNameMap[REFERENCE]            = "REFERENCE";
133   _typeNameMap[DATATYPE]             = "DATATYPE";
134 }
135
136 TypeOfElem ProcInvoc::getTypeOfNode(YACS::ENGINE::Node* node)
137 {
138   TypeOfElem nodeType = UNKNOWN;
139   if      (dynamic_cast<YACS::ENGINE::Bloc*>(node))             nodeType = BLOC;
140   else if (dynamic_cast<YACS::ENGINE::PythonNode*>(node))       nodeType = PYTHONNODE;
141   else if (dynamic_cast<YACS::ENGINE::PyFuncNode*>(node))       nodeType = PYFUNCNODE;
142   else if (dynamic_cast<YACS::ENGINE::CORBANode*>(node))        nodeType = CORBANODE;
143   else if (dynamic_cast<YACS::ENGINE::CppNode*>(node))          nodeType = CPPNODE;
144   else if (dynamic_cast<YACS::ENGINE::SalomeNode*>(node))       nodeType = SALOMENODE;
145   else if (dynamic_cast<YACS::ENGINE::SalomePythonNode*>(node)) nodeType = SALOMEPYTHONNODE;
146   else if (dynamic_cast<YACS::ENGINE::XmlNode*>(node))          nodeType = XMLNODE;
147   else if (dynamic_cast<YACS::ENGINE::SplitterNode*>(node))     nodeType = SPLITTERNODE;
148   else if (dynamic_cast<YACS::ENGINE::ForLoop*>(node))          nodeType = FORLOOP;
149   else if (dynamic_cast<YACS::ENGINE::WhileLoop*>(node))        nodeType = WHILELOOP;
150   else if (dynamic_cast<YACS::ENGINE::Switch*>(node))           nodeType = SWITCH;
151   else if (dynamic_cast<YACS::ENGINE::ForEachLoopGen*>(node))      nodeType = FOREACHLOOP;
152   else if (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(node))    nodeType = OPTIMIZERLOOP;
153   else if (dynamic_cast<YACS::ENGINE::PresetNode*>(node))       nodeType = PRESETNODE;
154   else if (dynamic_cast<YACS::ENGINE::OutNode*>(node))          nodeType = OUTNODE;
155   else if (dynamic_cast<YACS::ENGINE::StudyInNode*>(node))      nodeType = STUDYINNODE;
156   else if (dynamic_cast<YACS::ENGINE::StudyOutNode*>(node))     nodeType = STUDYOUTNODE;
157   return nodeType;
158 }
159
160 TypeOfElem ProcInvoc::getTypeOfPort(YACS::ENGINE::DataPort* port)
161 {
162   TypeOfElem portType = UNKNOWN;
163   if      (dynamic_cast<YACS::ENGINE::InputPort*>(port))            portType = INPUTPORT;
164   else if (dynamic_cast<YACS::ENGINE::OutputPort*>(port))           portType = OUTPUTPORT;
165   else if (dynamic_cast<YACS::ENGINE::InputDataStreamPort*>(port))  portType = INPUTDATASTREAMPORT;
166   else if (dynamic_cast<YACS::ENGINE::OutputDataStreamPort*>(port)) portType = OUTPUTDATASTREAMPORT;
167   return portType;
168 }
169
170 std::string ProcInvoc::getTypeName(TypeOfElem type)
171 {
172   if (_typeNameMap.count(type))
173     return _typeNameMap[type];
174   else
175     return "UNKNOWN";
176 }
177
178 // ----------------------------------------------------------------------------
179
180 CommandAddNodeFromCatalog::CommandAddNodeFromCatalog(YACS::ENGINE::Catalog *catalog,
181                                                      std::string compo,
182                                                      std::string type,
183                                                      std::string position,
184                                                      std::string name,
185                                                      bool newCompoInst,
186                                                      int swCase)
187   : Command(), _catalog(catalog), _compoName(compo), _typeName(type),
188     _position(position), _name(name), _newCompoInst(newCompoInst), _swCase(swCase)
189 {
190   DEBTRACE("CommandAddNodeFromCatalog " << compo << " " << type <<  " " << position <<  " " << name);
191   _node=0;
192   _snode=0;
193 }
194
195 std::string CommandAddNodeFromCatalog::dump()
196 {
197   string ret ="CommandAddNodeFromCatalog " + _compoName + " " + _typeName + " " +  _position + " " + _name;
198   return ret;
199 }
200
201 YACS::ENGINE::Node *CommandAddNodeFromCatalog::getNode()
202 {
203   return _node;
204 }
205
206 YACS::HMI::SubjectNode *CommandAddNodeFromCatalog::getSubjectNode()
207 {
208   return _snode;
209 }
210
211 bool CommandAddNodeFromCatalog::localExecute()
212 {
213   DEBTRACE("CommandAddNodeFromCatalog::localExecute");
214
215   Node *son = 0;
216   Node *nodeToClone = 0;
217   try
218     {
219       if (_compoName.empty())
220         {
221           if (_catalog->_nodeMap.count(_typeName))
222             nodeToClone = _catalog->_nodeMap[_typeName];
223           else if (_catalog->_composednodeMap.count(_typeName))
224             nodeToClone = _catalog->_composednodeMap[_typeName];
225         }
226       else
227         if (_catalog->_componentMap.count(_compoName))
228           {
229             YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compoName];
230             if (compodef->_serviceMap.count(_typeName))
231               nodeToClone = compodef->_serviceMap[_typeName];
232           }
233       if (nodeToClone)
234         _typeNode = ProcInvoc::getTypeOfNode(nodeToClone);
235
236       GuiContext::getCurrent()->setCurrentCatalog(_catalog);
237       Proc* proc = GuiContext::getCurrent()->getProc();
238       Node* node = proc;
239       ServiceNode *service = 0;
240
241       if (!_position.empty()) node = proc->getChildByName(_position);
242       ComposedNode* father =dynamic_cast<ComposedNode*> (node);
243       if (father && nodeToClone)
244         {
245           son = nodeToClone->clone(0);
246           son->setName(_name);
247           service = dynamic_cast<ServiceNode*>(son);
248         }
249
250       // Node creation eventually reusing old component instance
251       ComponentInstance *compo = 0;
252       if (service)
253         compo = service->getComponent();
254
255       if(compo)
256         {
257           std::string compoName=compo->getCompoName();
258           DEBTRACE(compoName);
259           std::string compoInstName=compo->getInstanceName();
260           DEBTRACE(compoInstName);
261           if(!_newCompoInst)
262             {
263               ComponentInstance *lastcompo = GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName];
264               DEBTRACE(lastcompo);
265               if(lastcompo)
266                 {
267                   DEBTRACE(lastcompo->getInstanceName());
268                   service->setComponent(lastcompo); // use the last component instance of the same type and not a new instance
269                 }
270               else
271                 GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
272             }
273           else
274             GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
275         }
276
277       if (son)
278         {
279           TypeOfElem fatherType = ProcInvoc::getTypeOfNode(father);
280           switch (fatherType)
281             {
282             case BLOC:
283               (dynamic_cast<YACS::ENGINE::Bloc*>(father))->edAddChild(son);
284               break;
285             case FORLOOP:
286               (dynamic_cast<YACS::ENGINE::ForLoop*>(father))->edSetNode(son);
287               break;
288             case WHILELOOP:
289               (dynamic_cast<YACS::ENGINE::WhileLoop*>(father))->edSetNode(son);
290               break;
291             case SWITCH:
292               (dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
293               break;
294             case FOREACHLOOP:
295               (dynamic_cast<YACS::ENGINE::ForEachLoopGen*>(father))->edSetNode(son);
296               break;
297             case OPTIMIZERLOOP:
298               (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
299               break;
300             default:
301               YASSERT(0);
302             }
303         }
304       _node = son;
305       if (!_node)
306         throw YACS::Exception("node from catalog is not correct: check if catalog is up to date!");
307
308       SubjectComposedNode *sfather = dynamic_cast<SubjectComposedNode*>(GuiContext::getCurrent()->_mapOfSubjectNode[father]);
309       _snode= sfather->addSubjectNode(_node, "", _catalog, _compoName, _typeName);
310       _snode->loadChildren();
311       _snode->loadLinks();
312     }
313   catch (Exception& ex)
314     {
315       DEBTRACE("CommandAddNode::localExecute() : " << ex.what());
316       setErrorMsg(ex);
317       if (son) delete son;
318       _node = 0;
319     }
320   return (_node != 0);
321 }
322
323 bool CommandAddNodeFromCatalog::localReverse()
324 {
325   DEBTRACE("CommandAddNodeFromCatalog::localReverse");
326   try
327     {
328       Proc* proc = GuiContext::getCurrent()->getProc();
329       string nodeName;
330       if (_position.empty())
331         nodeName= _name;
332       else
333         nodeName = _position + "." + _name;
334       DEBTRACE(nodeName);
335       _node = proc->getChildByName(nodeName);
336       YASSERT(_node);
337       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_node));
338       _snode = GuiContext::getCurrent()->_mapOfSubjectNode[_node];
339
340       Subject *father=_snode->getParent();
341       DEBTRACE(father);
342       DEBTRACE(father->getName());
343       Subject::erase(_snode);
344       _snode= 0;
345       _node = 0;
346       if (father)
347         {
348           DEBTRACE("REMOVE");
349           father->select(true);
350           father->update(REMOVE,0,0);
351         }
352       return true;
353     }
354   catch (Exception& ex)
355     {
356       DEBTRACE("CommandAddNodeFromCatalog::localReverse(): " << ex.what());
357       setErrorMsg(ex);
358       return false;
359     }
360 }
361
362 // ----------------------------------------------------------------------------
363
364 CommandReparentNode::CommandReparentNode(std::string position,
365                                          std::string newParent)
366   : Command(), _position(position), _newParent(newParent)
367 {
368   DEBTRACE("CommandReparentNode::CommandReparentNode " << _position << " " << _newParent);
369   _oldParent = "";
370 }
371
372 std::string CommandReparentNode::dump()
373 {
374   string ret ="CommandReparentNode " + _position + " " + _newParent;
375   return ret;
376 }
377
378 bool CommandReparentNode::localExecute()
379 {
380   DEBTRACE("CommandReparentNode::localExecute");
381   Proc* proc = GuiContext::getCurrent()->getProc();
382   Node* node = 0;
383   try
384     {
385       if (_position == proc->getName())
386         throw YACS::Exception("Reparent the proc (main bloc) is impossible");
387       node = proc->getChildByName(_position);
388       ComposedNode *oldFather = node->getFather();
389       ComposedNode *newFather = proc;
390       Node *newF = 0;
391       if (_newParent != proc->getName())
392         {
393           newF = proc->getChildByName(_newParent);
394           newFather = dynamic_cast<ComposedNode*>(newF);
395         }
396       if (!newFather)
397         throw YACS::Exception("new parent must be a composed node");
398       if (oldFather == newFather)
399         throw YACS::Exception("no need to reparent to the same parent");
400       if (ComposedNode *cnode = dynamic_cast<ComposedNode*>(node))
401         if (cnode->isInMyDescendance(newFather))
402           throw YACS::Exception("reparent a node to one of it's children is impossible");
403       if (Loop *loop = dynamic_cast<Loop*>(newFather))
404         if (!loop->edGetDirectDescendants().empty())
405           throw YACS::Exception("Already a node in a new parent of Loop type");
406       if (DynParaLoop * dpl = dynamic_cast<DynParaLoop*>(newFather))
407         if (dpl->getExecNode() != NULL)
408           throw YACS::Exception("Already an execution node in the new parent of type dynamic loop");
409       Node *nodeSameName = 0;
410       try
411         {
412           nodeSameName = newFather->getChildByName(node->getName());
413         }
414       catch (Exception& e)
415         {
416         }
417       if (nodeSameName)
418         throw YACS::Exception("there is already a child of same name in the new parent");
419       SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
420       Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
421       Subject *subn = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
422       SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
423       SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
424       //save existing links
425       snode->saveLinks();
426       snode->removeExternalLinks();
427       snode->removeExternalControlLinks();
428       sop->houseKeepingAfterCutPaste(true, snode);
429       oldFather->edRemoveChild(node);
430       newFather->edAddChild(node);
431       snp->houseKeepingAfterCutPaste(false, snode);
432       //restore links
433       snode->restoreLinks();
434       if (oldFather == proc) _oldParent = proc->getName();
435       else _oldParent = proc->getChildName(oldFather);
436       _newpos = proc->getChildName(node);
437       sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
438       snp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
439       snode->recursiveUpdate(RENAME, 0, snode);
440       snode->_parent = snp;
441     }
442   catch (Exception& ex)
443     {
444       DEBTRACE("CommandReparentNode::localExecute() : " << ex.what());
445       setErrorMsg(ex);
446       node = 0;
447     }
448   catch (...)
449     {
450       GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
451       node = 0;
452     }
453   return (node != 0); 
454 }
455
456 bool CommandReparentNode::localReverse()
457 {
458   DEBTRACE("CommandReparentNode::localReverse " << _newpos << " " << _oldParent);
459   Proc* proc = GuiContext::getCurrent()->getProc();
460   Node* node = 0;
461   try
462     {
463       node = proc->getChildByName(_newpos);
464       ComposedNode *father = node->getFather();
465       ComposedNode *oldFather = proc;
466       Node *oldF = 0;
467       if (_oldParent != proc->getName())
468         {
469           oldF = proc->getChildByName(_oldParent);
470           oldFather = dynamic_cast<ComposedNode*>(oldF);
471         }
472       SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
473       Subject *subn = GuiContext::getCurrent()->_mapOfSubjectNode[father];
474       Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
475       SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
476       SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
477       //save existing links
478       snode->saveLinks();
479       snode->removeExternalLinks();
480       snode->removeExternalControlLinks();
481       snp->houseKeepingAfterCutPaste(true, snode);
482       father->edRemoveChild(node);
483       oldFather->edAddChild(node);
484       sop->houseKeepingAfterCutPaste(false, snode);
485       //restore links
486       snode->restoreLinks();
487       snp->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
488       sop->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
489       snode->recursiveUpdate(RENAME, 0, snode);
490       snode->_parent = sop;
491     }
492   catch (Exception& ex)
493     {
494       DEBTRACE("CommandReparentNode::localReverse() : " << ex.what());
495       setErrorMsg(ex);
496       node = 0;
497     }
498   catch (...)
499     {
500       GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
501       node = 0;
502     }
503   return (node != 0); 
504 }
505
506 // ----------------------------------------------------------------------------
507 CommandPutInComposedNode::CommandPutInComposedNode(std::string position,
508                                                    std::string newParent,
509                                                    std::string type,
510                                                    bool toSaveRestoreLinks)
511   : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
512 {
513   DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
514   _newpos ="";
515 }
516
517 std::string CommandPutInComposedNode::dump()
518 {
519   string save = _toSaveRestoreLinks ? "true" : "false";
520   string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save;
521   return ret;
522 }
523
524
525 bool CommandPutInComposedNode::localExecute()
526 {
527   DEBTRACE("CommandPutInComposedNode::localExecute");
528   Proc* proc = GuiContext::getCurrent()->getProc();
529   Node* node = 0;
530   try
531     {
532       if (_position == proc->getName())
533         throw YACS::Exception("You cannot put the proc (main bloc) in a " + _type);
534       node = proc->getChildByName(_position);
535       ComposedNode *oldFather = node->getFather();
536       SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
537       Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
538       SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
539       if (_toSaveRestoreLinks)
540         snode->saveLinks(); //save existing links
541       //remove external links
542       snode->removeExternalLinks();
543       snode->removeExternalControlLinks();
544       //remove subject node from subject old father
545       sop->houseKeepingAfterCutPaste(true, snode);
546       //remove node from old father
547       oldFather->edRemoveChild(node);
548       //refresh node views
549       sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
550
551       // try to find a node with the given name:
552       //   success: use it as target composed node
553       //   fail:    create such a node and use it
554       std::list<Node*> children = proc->getChildren();
555       Node* composednode = 0;
556       SubjectNode *scomposednode = 0;
557       for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
558         {
559           if ( _newParent == (*it)->getName() )
560             {
561               //get an existing ComposedNode with name _newParent
562               composednode = (*it);
563               break;
564             }
565         }
566       // target node was found
567       if ( composednode )
568         {
569           scomposednode = GuiContext::getCurrent()->_mapOfSubjectNode[composednode];
570         }
571       // creation of target node
572       else 
573         {
574           //create a ComposedNode (type _type) with name _newParent
575           YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
576           Node* nodeToClone = catalog->_composednodeMap[_type];
577           composednode = nodeToClone->cloneWithoutCompAndContDeepCpy(0);
578           composednode->setName(_newParent);
579           //add the new composednode as child of oldfather
580           oldFather->edAddChild(composednode);
581           //create the subject composednode
582           scomposednode = sop->addSubjectNode(composednode,"",catalog,"",_type);
583         }
584
585       //add the old node as child of new composednode
586       (dynamic_cast<YACS::ENGINE::ComposedNode*>(composednode))->edAddChild(node);
587       _newpos = proc->getChildName(node);
588       //add the subject node to subject composednode
589       (dynamic_cast<SubjectComposedNode*>(scomposednode))->houseKeepingAfterCutPaste(false, snode);
590       snode->setParent(scomposednode);
591       if (_toSaveRestoreLinks)
592         snode->restoreLinks(); //restore links
593       //refresh all views
594       scomposednode->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
595       snode->recursiveUpdate(RENAME, 0, snode);
596       snode->select(true);
597     }
598   catch (Exception& ex)
599     {
600       DEBTRACE("CommandPutInComposedNode::localExecute() : " << ex.what());
601       setErrorMsg(ex);
602       node = 0;
603     }
604   catch (...)
605     {
606       GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
607       node = 0;
608     }
609   return (node != 0);
610 }
611
612 bool CommandPutInComposedNode::localReverse()
613 {
614   DEBTRACE("CommandPutInComposedNode::localReverse");
615   Proc* proc = GuiContext::getCurrent()->getProc();
616   Node* node = 0;
617   try
618     {
619       YASSERT(_newpos != proc->getName())
620       node = proc->getChildByName(_newpos);
621       ComposedNode *oldFather = node->getFather();
622       SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
623       Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
624       SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
625       //save existing links
626       snode->saveLinks();
627       //remove external links
628       snode->removeExternalLinks();
629       snode->removeExternalControlLinks();
630       //remove subject node from subject old father
631       sop->houseKeepingAfterCutPaste(true, snode);
632       //remove node from old father
633       oldFather->edRemoveChild(node);
634       //refresh node views, temporary paste in proc to keep widgets associated to node
635       sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
636       GuiContext::getCurrent()->getSubjectProc()->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
637
638       //remove composed node oldFather
639       ComposedNode *oldGrandFather = oldFather->getFather();
640       Subject *subog = GuiContext::getCurrent()->_mapOfSubjectNode[oldGrandFather];
641       SubjectComposedNode* sogp = dynamic_cast<SubjectComposedNode*>(subog);
642       Subject::erase(sop);
643
644        //add the old node as child of new composednode
645       oldGrandFather->edAddChild(node);
646       _newpos = proc->getChildName(node);
647       //add the subject node to subject composednode
648       sogp->houseKeepingAfterCutPaste(false, snode);
649       snode->setParent(sogp);
650       //restore links
651       snode->restoreLinks();
652       //refresh all views
653       GuiContext::getCurrent()->getSubjectProc()->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
654       sogp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
655       snode->recursiveUpdate(RENAME, 0, snode);
656       snode->select(true);
657     }
658   catch (Exception& ex)
659     {
660       DEBTRACE("CommandPutInComposedNode::localReverse() : " << ex.what());
661       setErrorMsg(ex);
662       node = 0;
663     }      
664   return (node != 0);
665 }
666 // ----------------------------------------------------------------------------
667
668 CommandCopyNode::CommandCopyNode(YACS::ENGINE::Proc *fromproc,
669                                  std::string position,
670                                  std::string newParent,
671                                  int swCase)
672   : Command(), _fromproc(fromproc), _position(position), _newParent(newParent), _newName(""), _clone(0), _case(swCase)
673 {
674   DEBTRACE("CommandCopyNode::CommandCopyNode " << _position << " " << _newParent);
675 }
676
677 std::string CommandCopyNode::dump()
678 {
679   string ret ="CommandCopyNode " + _position + " " + _newParent;
680   return ret;
681 }
682
683 YACS::ENGINE::Node *CommandCopyNode::getNode()
684 {
685   return _clone;
686 }
687
688 bool CommandCopyNode::localExecute()
689 {
690   DEBTRACE("CommandCopyNode::localExecute");
691   Proc* proc = GuiContext::getCurrent()->getProc();
692   Node* node = 0;
693   try
694     {
695       if (_position == _fromproc->getName())
696         throw YACS::Exception("Copy the proc (main bloc) is impossible");
697       node = _fromproc->getChildByName(_position);
698       ComposedNode *oldFather = node->getFather();
699       ComposedNode *newFather = proc;
700       Node *newF = 0;
701       if (_newParent != proc->getName())
702         {
703           newF = proc->getChildByName(_newParent);
704           newFather = dynamic_cast<ComposedNode*>(newF);
705         }
706       if (!newFather)
707         throw YACS::Exception("new parent must be a composed node");
708       if (Loop *loop = dynamic_cast<Loop*>(newFather))
709         if (!loop->edGetDirectDescendants().empty())
710           throw YACS::Exception("Already a node in a new parent of Loop type");
711       //_clone = node->cloneWithoutCompAndContDeepCpy(newFather);
712       _clone = node->cloneWithoutCompAndContDeepCpy(0);
713       if (!_clone)
714         throw YACS::Exception("Node cannot be cloned");
715       int nodeSuffix = -1;
716       bool sameName = true;
717       stringstream s;
718       do
719         {
720           s.str("");
721           s << node->getName();
722           if (nodeSuffix >= 0) // --- first try <0 means without suffix
723             s << nodeSuffix;
724           DEBTRACE(s.str());
725           try
726             {
727               Node *nodeSameName = newFather->getChildByName(s.str());
728             }
729           catch (Exception& e)
730             {
731               sameName = false;
732             }
733           nodeSuffix++;
734         }
735       while(sameName);
736       _clone->setName(s.str());
737       _newName = _clone->getName();
738
739       if (YACS::ENGINE::Switch* theswitch = dynamic_cast<YACS::ENGINE::Switch*>(newFather))
740         {
741           DEBTRACE("father is a switch " << newFather->getName());
742           int theCase=_case;
743           if(theswitch->edGetNode(_case))
744             {
745               //the case is already used. Try another one
746               theCase=theswitch->getMaxCase()+1;
747             }
748           theswitch->edSetNode(theCase,_clone);
749         }
750       else
751         newFather->edAddChild(_clone);
752
753       _newName = _clone->getQualifiedName();
754       DEBTRACE(_newName);
755
756       SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
757       SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(sub);
758       SubjectNode *son = snp->addSubjectNode(_clone);
759       son->loadChildren();
760       son->loadLinks();
761     }
762   catch (Exception& ex)
763     {
764       DEBTRACE("CommandCopyNode::localExecute() : " << ex.what());
765       setErrorMsg(ex);
766       _clone = 0;
767     }
768   return (_clone != 0); 
769 }
770
771 bool CommandCopyNode::localReverse()
772 {
773   DEBTRACE("CommandCopyNode::localReverse " << _position << " " << _newParent);
774   try
775     {
776       Proc* proc = GuiContext::getCurrent()->getProc();
777       string nodeName = _newParent + "." + _newName;
778       if (_newParent == proc->getName())
779         nodeName = _newName;
780       DEBTRACE(nodeName);
781       _clone = proc->getChildByName(nodeName);
782
783       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_clone));
784       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[_clone];
785       Subject *father = snode->getParent();
786       Subject::erase(snode);
787       _clone = 0;
788       if (father)
789         {
790           DEBTRACE("REMOVE");
791           father->select(true);
792           father->update(REMOVE,0,0);
793         }
794       return true;
795     }
796   catch (Exception& ex)
797     {
798       DEBTRACE("CommandCopyNode::localReverse(): " << ex.what());
799       setErrorMsg(ex);
800       return false;
801     }
802   return true;
803 }
804
805 // ----------------------------------------------------------------------------
806
807 CommandRenameNode::CommandRenameNode(std::string position, std::string name)
808   : Command(), _position(position), _name(name)
809 {
810   DEBTRACE("CommandRenameNode::CommandRenameNode " << _position << " " << _name);
811   _oldName ="";
812   _newpos="";
813 }
814
815 std::string CommandRenameNode::dump()
816 {
817   string ret ="CommandRenameNode " + _position + " " + _name;
818   return ret;
819 }
820
821 bool CommandRenameNode::localExecute()
822 {
823   DEBTRACE("CommandRenameNode::localExecute");
824   Proc* proc = GuiContext::getCurrent()->getProc();
825   Node* node = proc;
826   try
827     {
828       if (_position != proc->getName()) node = proc->getChildByName(_position);
829       _oldName = node->getName();
830       node->setName(_name);
831       if (node == proc)
832         _newpos = _name;
833       else
834         _newpos = proc->getChildName(node);
835       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
836       if (snode)
837         snode->recursiveUpdate(RENAME, 0, snode);
838     }
839   catch (Exception& ex)
840     {
841       DEBTRACE("CommandRenameNode::localExecute() : " << ex.what());
842       setErrorMsg(ex);
843       node = 0;
844     }
845   return (node != 0); 
846 }
847
848 bool CommandRenameNode::localReverse()
849 {
850   DEBTRACE("CommandRenameNode::localReverse");
851   Proc* proc = GuiContext::getCurrent()->getProc();
852   Node* node = proc;
853   try
854     {
855       if (_newpos != proc->getName()) node = proc->getChildByName(_newpos);
856       YASSERT(node->getName() == _name);
857       node->setName(_oldName);
858       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
859       if (snode)
860         snode->recursiveUpdate(RENAME, 0, snode);
861     }
862   catch (Exception& ex)
863     {
864       DEBTRACE("CommandRenameNode::localReverse() : " << ex.what());
865       setErrorMsg(ex);
866       node = 0;
867     }
868   return (node != 0); 
869 }
870
871 // ----------------------------------------------------------------------------
872
873 CommandRenameContainer::CommandRenameContainer(std::string oldName, std::string newName)
874   : Command(), _oldName(oldName), _newName(newName)
875 {
876   DEBTRACE("CommandRenameContainer::CommandRenameContainer " << _oldName << " " << _newName);
877 }
878
879 std::string CommandRenameContainer::dump()
880 {
881   string ret ="CommandRenameContainer " +_oldName + " " + _newName;
882   return ret;
883 }
884
885 bool CommandRenameContainer::localExecute()
886 {
887   DEBTRACE("CommandRenameContainer::localExecute");
888   Proc* proc = GuiContext::getCurrent()->getProc();
889   Container *container = 0;
890   try
891     {
892       YASSERT(proc->containerMap.count(_oldName));
893       container = proc->containerMap[_oldName];
894       if (proc->containerMap.count(_newName))
895         {
896           GuiContext::getCurrent()->_lastErrorMessage = "Container name already existing";
897           return 0;
898         }
899       proc->containerMap.erase(_oldName);
900       container->setName(_newName);
901       proc->containerMap[_newName] = container;
902       YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
903       SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[container]);
904       scont-> update(RENAME, 0, scont);
905       scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
906     }
907   catch (Exception& ex)
908     {
909       DEBTRACE("CommandRenameContainer::localExecute() : " << ex.what());
910       setErrorMsg(ex);
911       container = 0;
912     }
913   return (container != 0); 
914 }
915
916 bool CommandRenameContainer::localReverse()
917 {
918   DEBTRACE("CommandRenameContainer::localReverse");
919   Proc* proc = GuiContext::getCurrent()->getProc();
920   Container *container = 0;
921   try
922     {
923       YASSERT(proc->containerMap.count(_newName));
924       container = proc->containerMap[_newName];
925       proc->containerMap.erase(_newName);
926       container->setName(_oldName);
927       proc->containerMap[_oldName] = container;
928       YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
929       SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[container]);
930       scont-> update(RENAME, 0, scont);
931       scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
932     }
933   catch (Exception& ex)
934     {
935       DEBTRACE("CommandRenameContainer::localReverse() : " << ex.what());
936       setErrorMsg(ex);
937       container = 0;
938     }
939   return (container != 0); 
940 }
941
942 // ----------------------------------------------------------------------------
943
944 CommandRenameInDataPort::CommandRenameInDataPort(std::string position,
945                                                  std::string oldName,
946                                                  std::string newName, TypeOfElem portType)
947   : Command(), _position(position), _oldName(oldName), _newName(newName), _portType(portType)
948 {
949   DEBTRACE("CommandRenameInDataPort::CommandRenameInDataPort "
950            << _position << " " << _oldName<< " " << _newName);
951 }
952
953 std::string CommandRenameInDataPort::dump()
954 {
955   string ret ="CommandRenameInDataPort " + _position + " " + _oldName + " " + _newName;
956   return ret;
957 }
958
959 bool CommandRenameInDataPort::localExecute()
960 {
961   DEBTRACE("CommandRenameInDataPort::localExecute");
962   Proc* proc = GuiContext::getCurrent()->getProc();
963   Node* node = proc;
964   try
965     {
966       if (_position != proc->getName()) node = proc->getChildByName(_position);
967       InPort * port = 0;
968
969       try
970         {
971           if(_portType==INPUTPORT)
972             port = node->getInputPort(_newName);
973           else
974             port = node->getInputDataStreamPort(_newName);
975         }
976       catch (Exception& e) {} // --- raised when no existing port with _newName
977       if (port)
978         throw Exception("there is already a port with the new name");
979
980       if(_portType==INPUTPORT)
981         port = node->getInputPort(_oldName);
982       else
983         port = node->getInputDataStreamPort(_oldName);
984       port->setName(_newName);
985       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
986       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
987       sport->update(RENAME, 0, sport);
988     }
989   catch (Exception& ex)
990     {
991       DEBTRACE("CommandRenameInDataPort::localExecute() : " << ex.what());
992       setErrorMsg(ex);
993       node = 0;
994     }
995   return (node != 0); 
996 }
997
998 bool CommandRenameInDataPort::localReverse()
999 {
1000   DEBTRACE("CommandRenameInDataPort::localReverse");
1001   Proc* proc = GuiContext::getCurrent()->getProc();
1002   Node* node = proc;
1003   try
1004     {
1005       if (_position != proc->getName()) node = proc->getChildByName(_position);
1006       InPort * port = 0;
1007
1008       try
1009         {
1010           if(_portType==INPUTPORT)
1011             port = node->getInputPort(_oldName);
1012           else
1013             port = node->getInputDataStreamPort(_oldName);
1014         }
1015       catch (Exception& e) {} // --- raised when no existing port with _newName
1016       if (port)
1017         throw Exception("there is already a port with the old name");
1018
1019       if(_portType==INPUTPORT)
1020         port = node->getInputPort(_newName);
1021       else
1022         port = node->getInputDataStreamPort(_newName);
1023       port->setName(_oldName);
1024       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1025       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1026       sport->update(RENAME, 0, sport);
1027     }
1028   catch (Exception& ex)
1029     {
1030       DEBTRACE("CommandRenameInDataPort::localReverse() : " << ex.what());
1031       setErrorMsg(ex);
1032       node = 0;
1033     }
1034   return (node != 0); 
1035 }
1036
1037 // ----------------------------------------------------------------------------
1038
1039 CommandRenameOutDataPort::CommandRenameOutDataPort(std::string position,
1040                                                    std::string oldName,
1041                                                    std::string newName, TypeOfElem portType)
1042   : Command(), _position(position), _oldName(oldName), _newName(newName), _portType(portType)
1043 {
1044   DEBTRACE("CommandRenameOutDataPort::CommandRenameOutDataPort "
1045            << _position << " " << _oldName<< " " << _newName);
1046 }
1047
1048 std::string CommandRenameOutDataPort::dump()
1049 {
1050   string ret ="CommandRenameOutDataPort "  + _position + " " + _oldName + " " + _newName;
1051   return ret;
1052 }
1053
1054 bool CommandRenameOutDataPort::localExecute()
1055 {
1056   DEBTRACE("CommandRenameOutDataPort::localExecute");
1057   Proc* proc = GuiContext::getCurrent()->getProc();
1058   Node* node = proc;
1059   try
1060     {
1061       if (_position != proc->getName()) node = proc->getChildByName(_position);
1062       OutPort * port = 0;
1063       try
1064         {
1065           if(_portType==OUTPUTPORT)
1066             port = node->getOutputPort(_newName);
1067           else
1068             port = node->getOutputDataStreamPort(_newName);
1069         }
1070       catch (Exception& e) {} // --- raised when no existing port with _newName
1071       if (port)
1072         throw Exception("there is already a port with the new name");
1073
1074       if(_portType==OUTPUTPORT)
1075         port = node->getOutputPort(_oldName);
1076       else
1077         port = node->getOutputDataStreamPort(_oldName);
1078       port->setName(_newName);
1079       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1080       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1081       sport->update(RENAME, 0, sport);
1082     }
1083   catch (Exception& ex)
1084     {
1085       DEBTRACE("CommandRenameOutDataPort::localExecute() : " << ex.what());
1086       setErrorMsg(ex);
1087       node = 0;
1088     }
1089   return (node != 0); 
1090 }
1091
1092 bool CommandRenameOutDataPort::localReverse()
1093 {
1094   DEBTRACE("CommandRenameOutDataPort::localReverse");
1095   Proc* proc = GuiContext::getCurrent()->getProc();
1096   Node* node = proc;
1097   try
1098     {
1099       if (_position != proc->getName()) node = proc->getChildByName(_position);
1100       OutPort * port = 0;
1101       try
1102         {
1103           if(_portType==OUTPUTPORT)
1104             port = node->getOutputPort(_oldName);
1105           else
1106             port = node->getOutputDataStreamPort(_oldName);
1107         }
1108       catch (Exception& e) {} // --- raised when no existing port with _newName
1109       if (port)
1110         throw Exception("there is already a port with the old name");
1111
1112       if(_portType==OUTPUTPORT)
1113         port = node->getOutputPort(_newName);
1114       else
1115         port = node->getOutputDataStreamPort(_newName);
1116       port->setName(_oldName);
1117       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1118       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1119       sport->update(RENAME, 0, sport);
1120     }
1121   catch (Exception& ex)
1122     {
1123       DEBTRACE("CommandRenameOutDataPort::localReverse() : " << ex.what());
1124       setErrorMsg(ex);
1125       node = 0;
1126     }
1127   return (node != 0); 
1128 }
1129
1130 // ----------------------------------------------------------------------------
1131
1132 CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog(YACS::ENGINE::Catalog* catalog,
1133                                                              std::string typeName)
1134   : Command(), _catalog(catalog), _typeName(typeName)
1135 {
1136   DEBTRACE("CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog: " << typeName);
1137 }
1138
1139 std::string CommandAddDataTypeFromCatalog::dump()
1140 {
1141   string ret ="CommandAddDataTypeFromCatalog " + _typeName;
1142   return ret;
1143 }
1144
1145 YACS::ENGINE::TypeCode *CommandAddDataTypeFromCatalog::getTypeCode()
1146 {
1147
1148   if (GuiContext::getCurrent()->getProc()->typeMap.count(_typeName))
1149     return GuiContext::getCurrent()->getProc()->typeMap[_typeName];
1150   else return 0;
1151 }
1152
1153 bool CommandAddDataTypeFromCatalog::localExecute()
1154 {
1155   DEBTRACE("CommandAddDataTypeFromCatalog::localExecute");
1156   Proc* proc = GuiContext::getCurrent()->getProc();
1157   if (proc->typeMap.count(_typeName))
1158     {
1159       DEBTRACE("typecode already existing in proc: " << _typeName);
1160       GuiContext::getCurrent()->_lastErrorMessage = "typeCode already existing in proc: " + _typeName;
1161       return false;
1162     }
1163   else
1164     if (_catalog->_typeMap.count(_typeName))
1165       {
1166         DEBTRACE("typecode found in catalog, cloned: " << _typeName);
1167         proc->typeMap[_typeName] = _catalog->_typeMap[_typeName]->clone();
1168         proc->typeMap[_typeName]->incrRef();
1169         SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
1170         SubjectDataType *son = sproc->addSubjectDataType(getTypeCode(), _typeName);
1171         return (son!=0);
1172       }
1173   GuiContext::getCurrent()->_lastErrorMessage = "typecode not found in catalog: " + _typeName;
1174   return false;
1175 }
1176
1177 bool CommandAddDataTypeFromCatalog::localReverse()
1178 {
1179   DEBTRACE("CommandAddDataTypeFromCatalog::localReverse");
1180   try
1181     {
1182       SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
1183       sproc->removeSubjectDataType(_typeName);
1184       return true;
1185     }
1186   catch (Exception& ex)
1187     {
1188       DEBTRACE("CommandAddDataTypeFromCatalog::localReverse(): " << ex.what());
1189       setErrorMsg(ex);
1190       return 0;
1191     }
1192 }
1193
1194
1195 // ----------------------------------------------------------------------------
1196
1197 CommandAddInputPortFromCatalog::CommandAddInputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1198                                                                std::string type,
1199                                                                std::string node,
1200                                                                std::string name)
1201   : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1202 {
1203   _inputPort = 0;
1204   _sip = 0;
1205 }
1206
1207 std::string CommandAddInputPortFromCatalog::dump()
1208 {
1209   string ret ="CommandAddInputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1210   return ret;
1211 }
1212
1213 YACS::ENGINE::InputPort *CommandAddInputPortFromCatalog::getInputPort()
1214 {
1215   return _inputPort;
1216 }
1217  
1218 SubjectInputPort* CommandAddInputPortFromCatalog::getSubjectInputPort()
1219 {
1220   return _sip;
1221 }
1222
1223 bool CommandAddInputPortFromCatalog::localExecute()
1224 {
1225   DEBTRACE("CommandAddInputPortFromCatalog::localExecute");
1226   InputPort *son = 0;
1227   try
1228     {
1229       Proc* proc = GuiContext::getCurrent()->getProc();
1230       Node* node = proc->getChildByName(_node);
1231       ElementaryNode* father = dynamic_cast<ElementaryNode*>(node);
1232       if (father)
1233         {
1234           //try proc types and then catalog if not in proc
1235           if(proc->typeMap.count(_typePort))
1236             son = father->edAddInputPort(_name, proc->typeMap[_typePort]);
1237           else if (_catalog->_typeMap.count(_typePort))
1238             son = father->edAddInputPort(_name, _catalog->_typeMap[_typePort]);
1239           else
1240             {
1241               DEBTRACE(_typePort << " not found in catalog " << _catalog);
1242               GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1243             }
1244         }
1245       _inputPort = son;
1246       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1247       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1248       _sip = snode->addSubjectInputPort(son, _name);
1249       snode->update(SYNCHRO,0,0); // when output port tab in node edition is visible
1250     }
1251   catch (Exception& ex)
1252     {
1253       DEBTRACE("CommandAddInputPortFromCatalog::localExecute() : " << ex.what());
1254       setErrorMsg(ex);
1255       if (son) delete son;
1256       _inputPort = 0;
1257     }
1258   return (_inputPort != 0);
1259 }
1260
1261 bool CommandAddInputPortFromCatalog::localReverse()
1262 {
1263   DEBTRACE("CommandAddInputPortFromCatalog::localReverse");
1264   try
1265     {
1266       Proc* proc = GuiContext::getCurrent()->getProc();
1267       Node *node = proc->getChildByName(_node);
1268       ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1269       YASSERT(enode);      
1270       _inputPort = enode->getInputPort(_name);
1271       YASSERT(_inputPort);
1272       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_inputPort));
1273       _sip = dynamic_cast<SubjectInputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_inputPort]);
1274       YASSERT(_sip);
1275
1276       Subject *father=_sip->getParent();
1277       Subject::erase(_sip);
1278       _sip = 0;
1279       _inputPort = 0;
1280       if (father)
1281         {
1282           DEBTRACE("REMOVE");
1283           father->select(true);
1284           father->update(REMOVE,0,0);
1285         }
1286       return true;
1287     }
1288   catch (Exception& ex)
1289     {
1290       DEBTRACE("CommandAddInputPortFromCatalog::localReverse(): " << ex.what());
1291       setErrorMsg(ex);
1292       return false;
1293     }
1294 }
1295
1296 // ----------------------------------------------------------------------------
1297
1298 CommandAddOutputPortFromCatalog::CommandAddOutputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1299                                                                  std::string type,
1300                                                                  std::string node,
1301                                                                  std::string name)
1302   : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1303 {
1304   _outputPort = 0;
1305   _sop = 0;
1306 }
1307
1308 std::string CommandAddOutputPortFromCatalog::dump()
1309 {
1310   string ret ="CommandAddOutputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1311   return ret;
1312 }
1313
1314 YACS::ENGINE::OutputPort *CommandAddOutputPortFromCatalog::getOutputPort()
1315 {
1316   return _outputPort;
1317 }
1318
1319 SubjectOutputPort* CommandAddOutputPortFromCatalog::getSubjectOutputPort()
1320 {
1321   return _sop;
1322 }
1323
1324 bool CommandAddOutputPortFromCatalog::localExecute()
1325 {
1326   DEBTRACE("CommandAddOutputPortFromCatalog::localExecute");
1327   OutputPort *son = 0;
1328   try
1329     {
1330       Proc* proc = GuiContext::getCurrent()->getProc();
1331       Node* node = proc->getChildByName(_node);
1332       ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1333       if (father)
1334         {
1335           //try proc types and then catalog if not in proc
1336           if(proc->typeMap.count(_typePort))
1337             son = father->edAddOutputPort(_name, proc->typeMap[_typePort]);
1338           else if (_catalog->_typeMap.count(_typePort))
1339             son = father->edAddOutputPort(_name, _catalog->_typeMap[_typePort]);
1340           else
1341             {
1342               DEBTRACE(_typePort << " not found in catalog");
1343               GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1344             }
1345         }
1346       _outputPort = son;
1347       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1348       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1349       _sop = snode->addSubjectOutputPort(son, _name);
1350       snode->update(SYNCHRO,0,0); // when input port tab in node edition is visible
1351     }
1352   catch (Exception& ex)
1353     {
1354       DEBTRACE("CommandAddOutputPortFromCatalog::localExecute() : " << ex.what());
1355       setErrorMsg(ex);
1356       if (son) delete son;
1357       _outputPort = 0;
1358     }
1359   return (_outputPort != 0);
1360 }
1361
1362 bool CommandAddOutputPortFromCatalog::localReverse()
1363 {
1364   DEBTRACE("CommandAddOutputPortFromCatalog::localReverse");
1365   try
1366     {
1367       Proc* proc = GuiContext::getCurrent()->getProc();
1368       Node *node = proc->getChildByName(_node);
1369       ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1370       YASSERT(enode);      
1371       _outputPort = enode->getOutputPort(_name);
1372       YASSERT(_outputPort);
1373       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_outputPort));
1374       _sop = dynamic_cast<SubjectOutputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_outputPort]);
1375       YASSERT(_sop);
1376
1377       Subject *father=_sop->getParent();
1378       Subject::erase(_sop);
1379       _sop = 0;
1380       _outputPort = 0;
1381       if (father)
1382         {
1383           DEBTRACE("REMOVE");
1384           father->select(true);
1385           father->update(REMOVE,0,0);
1386         }
1387       return true;
1388     }
1389   catch (Exception& ex)
1390     {
1391       DEBTRACE("CommandAddOutputPortFromCatalog::localReverse(): " << ex.what());
1392       setErrorMsg(ex);
1393       return false;
1394     }
1395 }
1396
1397 // ----------------------------------------------------------------------------
1398
1399 CommandAddIDSPortFromCatalog::CommandAddIDSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1400                                                            std::string type,
1401                                                            std::string node,
1402                                                            std::string name)
1403   : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1404 {
1405   _IDSPort = 0;
1406   _sip = 0;
1407 }
1408
1409 std::string CommandAddIDSPortFromCatalog::dump()
1410 {
1411   string ret ="CommandAddIDSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1412   return ret;
1413 }
1414
1415 YACS::ENGINE::InputDataStreamPort *CommandAddIDSPortFromCatalog::getIDSPort()
1416 {
1417   DEBTRACE("CommandAddIDSPortFromCatalog");
1418   return _IDSPort;
1419 }
1420
1421 SubjectInputDataStreamPort* CommandAddIDSPortFromCatalog::getSubjectIDSPort()
1422 {
1423   return _sip;
1424 }
1425
1426 bool CommandAddIDSPortFromCatalog::localExecute()
1427 {
1428   DEBTRACE("CommandAddIDSPortFromCatalog::localExecute");
1429   InputDataStreamPort *son = 0;
1430   try
1431     {
1432       Proc* proc = GuiContext::getCurrent()->getProc();
1433       Node* node = proc->getChildByName(_node);
1434       ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1435       if (father)
1436         {
1437           if (_catalog->_typeMap.count(_typePort))
1438             son = father->edAddInputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1439           else
1440             {
1441               DEBTRACE(_typePort << " not found in catalog");
1442               GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1443             }
1444         }
1445       _IDSPort = son;
1446       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1447       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1448       _sip = snode->addSubjectIDSPort(son, _name);
1449     }
1450   catch (Exception& ex)
1451     {
1452       DEBTRACE("CommandAddIDSPortFromCatalog::localExecute() : " << ex.what());
1453       setErrorMsg(ex);
1454       if (son) delete son;
1455       _IDSPort = 0;
1456     }
1457   return (_IDSPort != 0);
1458 }
1459
1460 bool CommandAddIDSPortFromCatalog::localReverse()
1461 {
1462   DEBTRACE("CommandAddIDSPortFromCatalog::localReverse");
1463   try
1464     {
1465       Proc* proc = GuiContext::getCurrent()->getProc();
1466       Node *node = proc->getChildByName(_node);
1467       ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1468       YASSERT(enode);      
1469       _IDSPort = enode->getInputDataStreamPort(_name);
1470       YASSERT(_IDSPort);
1471       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_IDSPort));
1472       _sip = dynamic_cast<SubjectInputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_IDSPort]);
1473       YASSERT(_sip);
1474
1475       Subject *father=_sip->getParent();
1476       Subject::erase(_sip);
1477       _IDSPort =0;
1478       _sip = 0;
1479       if (father)
1480         {
1481           DEBTRACE("REMOVE");
1482           father->select(true);
1483           father->update(REMOVE,0,0);
1484         }
1485       return true;
1486     }
1487   catch (Exception& ex)
1488     {
1489       DEBTRACE("CommandAddIDSPortFromCatalog::localReverse(): " << ex.what());
1490       setErrorMsg(ex);
1491       return false;
1492     }
1493 }
1494  
1495 // ----------------------------------------------------------------------------
1496
1497 CommandAddODSPortFromCatalog::CommandAddODSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1498                                                            std::string type,
1499                                                            std::string node,
1500                                                            std::string name)
1501   : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1502 {
1503   DEBTRACE("CommandAddODSPortFromCatalog");
1504   _ODSPort = 0;
1505   _sop = 0;
1506 }
1507
1508 std::string CommandAddODSPortFromCatalog::dump()
1509 {
1510   string ret ="CommandAddODSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1511   return ret;
1512 }
1513
1514 YACS::ENGINE::OutputDataStreamPort *CommandAddODSPortFromCatalog::getODSPort()
1515 {
1516   return _ODSPort;
1517 }
1518
1519 SubjectOutputDataStreamPort* CommandAddODSPortFromCatalog::getSubjectODSPort()
1520 {
1521   return _sop;
1522 }
1523
1524 bool CommandAddODSPortFromCatalog::localExecute()
1525 {
1526   DEBTRACE("CommandAddODSPortFromCatalog::localExecute");
1527   OutputDataStreamPort *son = 0;
1528   try
1529     {
1530       Proc* proc = GuiContext::getCurrent()->getProc();
1531       Node* node = proc->getChildByName(_node);
1532       ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1533       if (father)
1534         {
1535           if (_catalog->_typeMap.count(_typePort))
1536             son = father->edAddOutputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1537           else
1538             {
1539               DEBTRACE(_typePort << " not found in catalog");
1540               GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1541             }
1542         }
1543       _ODSPort = son;
1544       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1545       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1546       _sop = snode->addSubjectODSPort(son, _name);
1547     }
1548   catch (Exception& ex)
1549     {
1550       DEBTRACE("CommandAddODSPortFromCatalog::localExecute() : " << ex.what());
1551       setErrorMsg(ex);
1552       if (son) delete son;
1553       _ODSPort = 0;
1554     }
1555   return (_ODSPort != 0);
1556 }
1557
1558 bool CommandAddODSPortFromCatalog::localReverse()
1559 {
1560   DEBTRACE("CommandAddODSPortFromCatalog::localReverse");
1561   try
1562     {
1563       Proc* proc = GuiContext::getCurrent()->getProc();
1564       Node *node = proc->getChildByName(_node);
1565       ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1566       YASSERT(enode);      
1567       _ODSPort = enode->getOutputDataStreamPort(_name);
1568       YASSERT(_ODSPort);
1569       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_ODSPort));
1570       _sop = dynamic_cast<SubjectOutputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_ODSPort]);
1571       YASSERT(_sop);
1572
1573       Subject *father=_sop->getParent();
1574       Subject::erase(_sop);
1575       _sop = 0;
1576       _ODSPort = 0;
1577       if (father)
1578         {
1579           DEBTRACE("REMOVE");
1580           father->select(true);
1581           father->update(REMOVE,0,0);
1582         }
1583       return true;
1584     }
1585   catch (Exception& ex)
1586     {
1587       DEBTRACE("CommandAddODSPortFromCatalog::localReverse(): " << ex.what());
1588       setErrorMsg(ex);
1589       return false;
1590     }
1591 }
1592
1593 // ----------------------------------------------------------------------------
1594
1595 /*! move up or down a port in the list of ports of a node.
1596  *  if isUp = 0, move down one step, if isUp = n>0, move up n steps.
1597  */
1598 CommandOrderInputPorts::CommandOrderInputPorts(std::string node,
1599                                                std::string port,
1600                                                int isUp)
1601   : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1602 {
1603   DEBTRACE("CommandOrderInputPorts");
1604 }
1605
1606 std::string CommandOrderInputPorts::dump()
1607 {
1608   ostringstream s;
1609   s << _isUp;
1610   string ret ="CommandOrderInputPorts " + _node + " " + _port + " " + s.str();
1611   return ret;
1612 }
1613
1614 bool CommandOrderInputPorts::localExecute()
1615 {
1616   DEBTRACE("CommandOrderInputPorts::localExecute " << _node << " " << _port  << " " << _isUp);
1617   ElementaryNode* father = 0;
1618   try
1619     {
1620       Proc* proc = GuiContext::getCurrent()->getProc();
1621       Node* node = proc->getChildByName(_node);
1622       father = dynamic_cast<ElementaryNode*> (node);
1623       if (!father) return false;
1624       InputPort *portToMove = father->getInputPort(_port);
1625       DEBTRACE(portToMove->getName());
1626
1627       list<InputPort*> plist = father->getSetOfInputPort();
1628       list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1629
1630       int isUp = _isUp;
1631       if (isUp)
1632         {
1633           if(pos == plist.begin())
1634             pos=plist.end(); // --- cycle
1635           else
1636             do { pos--; isUp--; } while (isUp);
1637         }
1638       else
1639         {
1640           pos++;
1641           if (pos == plist.end())
1642             pos = plist.begin(); // --- cycle
1643           else
1644             pos++; // --- insert before the 2nd next port
1645         }
1646
1647       InputPort *portBefore = 0;
1648       if (pos != plist.end())
1649         portBefore = (*pos);
1650
1651       plist.remove(portToMove);
1652       if (portBefore)
1653         {
1654           DEBTRACE(portBefore->getName());
1655           pos = find(plist.begin(), plist.end(), portBefore);
1656           _rank = 0;
1657           for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1658             _rank++;
1659           plist.insert(pos, portToMove);
1660         }
1661       else
1662         {
1663           _rank = plist.size();
1664           plist.push_back(portToMove);
1665         }
1666       father->edOrderInputPorts(plist);
1667       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1668       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1669       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1670       snode->update(ORDER, true, sport);
1671       snode->update(SYNCHRO, true, sport); // --- synchronise edition and scene
1672     }
1673   catch (Exception& ex)
1674     {
1675       DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1676       setErrorMsg(ex);
1677       father = 0;
1678     }
1679   return (father != 0);
1680 }
1681
1682 bool CommandOrderInputPorts::localReverse()
1683 {
1684   DEBTRACE("CommandOrderInputPorts::localReverse " << _node << " " << _port  << " " << _isUp);
1685   ElementaryNode* father = 0;
1686   try
1687     {
1688       int isUpRev = -_isUp;
1689       if (isUpRev == 0) isUpRev =1;
1690       Proc* proc = GuiContext::getCurrent()->getProc();
1691       Node* node = proc->getChildByName(_node);
1692       father = dynamic_cast<ElementaryNode*> (node);
1693       if (!father) return false;
1694       InputPort *portToMove = father->getInputPort(_port);
1695       DEBTRACE(portToMove->getName());
1696
1697       list<InputPort*> plist = father->getSetOfInputPort();
1698       list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1699
1700       if (isUpRev>0)
1701         {
1702           if(pos == plist.begin())
1703             pos=plist.end(); // --- cycle
1704           else
1705             do { pos--; isUpRev--; } while (isUpRev);
1706         }
1707       else
1708         {
1709           pos++;
1710           if (pos == plist.end())
1711             pos = plist.begin(); // --- cycle
1712           else
1713             do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1714         }
1715
1716       InputPort *portBefore = 0;
1717       if (pos != plist.end())
1718         portBefore = (*pos);
1719
1720       plist.remove(portToMove);
1721       if (portBefore)
1722         {
1723           DEBTRACE(portBefore->getName());
1724           pos = find(plist.begin(), plist.end(), portBefore);
1725           _rank = 0;
1726           for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1727             _rank++;
1728           plist.insert(pos, portToMove);
1729         }
1730       else
1731         {
1732           _rank = plist.size();
1733           plist.push_back(portToMove);
1734         }
1735       father->edOrderInputPorts(plist);
1736       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1737       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1738       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1739       snode->update(ORDER, true, sport);
1740       snode->update(SYNCHRO, true, sport); // --- synchronise edition and scene
1741     }
1742   catch (Exception& ex)
1743     {
1744       DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1745       setErrorMsg(ex);
1746       father = 0;
1747     }
1748   return (father != 0);
1749 }
1750
1751 // ----------------------------------------------------------------------------
1752
1753 /*! move up or down a port in the list of ports of a node.
1754  *  if isUp = 0, move down one step, if isUp = n>0, move up n steps.
1755  */
1756 CommandOrderOutputPorts::CommandOrderOutputPorts(std::string node,
1757                                                  std::string port,
1758                                                  int isUp)
1759   : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1760 {
1761   DEBTRACE("CommandOrderOutputPorts");
1762 }
1763
1764 std::string CommandOrderOutputPorts::dump()
1765 {
1766   ostringstream s;
1767   s << _isUp;
1768   string ret ="CommandOrderOutputPorts " + _node + " " + _port + " " + s.str();
1769   return ret;
1770 }
1771
1772 bool CommandOrderOutputPorts::localExecute()
1773 {
1774   DEBTRACE("CommandOrderOutputPorts::localExecute " << _node << " " << _port  << " " << _isUp);
1775   ElementaryNode* father = 0;
1776   try
1777     {
1778       Proc* proc = GuiContext::getCurrent()->getProc();
1779       Node* node = proc->getChildByName(_node);
1780       father = dynamic_cast<ElementaryNode*> (node);
1781       if (!father) return false;
1782       OutputPort *portToMove = father->getOutputPort(_port);
1783       DEBTRACE(portToMove->getName());
1784
1785       list<OutputPort*> plist = father->getSetOfOutputPort();
1786       list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1787
1788       int isUp = _isUp;
1789       if (isUp)
1790         {
1791           if(pos == plist.begin())
1792             pos=plist.end(); // --- cycle
1793           else
1794             do { pos--; isUp--; } while (isUp);
1795         }
1796       else
1797         {
1798           pos++;
1799           if (pos == plist.end())
1800             pos = plist.begin(); // --- cycle
1801           else
1802             pos++; // --- insert before the 2nd next port
1803         }
1804
1805       OutputPort *portBefore = 0;
1806       if (pos != plist.end())
1807         portBefore = (*pos);
1808
1809       plist.remove(portToMove);
1810       if (portBefore)
1811         {
1812           DEBTRACE(portBefore->getName());
1813           pos = find(plist.begin(), plist.end(), portBefore);
1814           _rank = 0;
1815           for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1816             _rank++;
1817           plist.insert(pos, portToMove);
1818         }
1819       else
1820         {
1821           _rank = plist.size();
1822           plist.push_back(portToMove);
1823         }
1824       father->edOrderOutputPorts(plist);
1825       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1826       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1827       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1828       snode->update(ORDER, false, sport);
1829       snode->update(SYNCHRO, false, sport); // --- synchronise edition and scene
1830     }
1831   catch (Exception& ex)
1832     {
1833       DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1834       setErrorMsg(ex);
1835       father = 0;
1836     }
1837   return (father != 0);
1838 }
1839
1840 bool CommandOrderOutputPorts::localReverse()
1841 {
1842   DEBTRACE("CommandOrderOutputPorts::localReverse " << _node << " " << _port  << " " << _isUp);
1843   ElementaryNode* father = 0;
1844   try
1845     {
1846       int isUpRev = -_isUp;
1847       if (isUpRev == 0) isUpRev =1;
1848       Proc* proc = GuiContext::getCurrent()->getProc();
1849       Node* node = proc->getChildByName(_node);
1850       father = dynamic_cast<ElementaryNode*> (node);
1851       if (!father) return false;
1852       OutputPort *portToMove = father->getOutputPort(_port);
1853       DEBTRACE(portToMove->getName());
1854
1855       list<OutputPort*> plist = father->getSetOfOutputPort();
1856       list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1857
1858       if (isUpRev>0)
1859         {
1860           if(pos == plist.begin())
1861             pos=plist.end(); // --- cycle
1862           else
1863             do { pos--; isUpRev--; } while (isUpRev);
1864         }
1865       else
1866         {
1867           pos++;
1868           if (pos == plist.end())
1869             pos = plist.begin(); // --- cycle
1870           else
1871             do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1872         }
1873
1874       OutputPort *portBefore = 0;
1875       if (pos != plist.end())
1876         portBefore = (*pos);
1877
1878       plist.remove(portToMove);
1879       if (portBefore)
1880         {
1881           DEBTRACE(portBefore->getName());
1882           pos = find(plist.begin(), plist.end(), portBefore);
1883           _rank = 0;
1884           for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1885             _rank++;
1886           plist.insert(pos, portToMove);
1887         }
1888       else
1889         {
1890           _rank = plist.size();
1891           plist.push_back(portToMove);
1892         }
1893       father->edOrderOutputPorts(plist);
1894       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1895       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1896       SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1897       snode->update(ORDER, false, sport);
1898       snode->update(SYNCHRO, false, sport); // --- synchronise edition and scene
1899     }
1900   catch (Exception& ex)
1901     {
1902       DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1903       setErrorMsg(ex);
1904       father = 0;
1905     }
1906   return (father != 0);
1907 }
1908
1909 // ----------------------------------------------------------------------------
1910
1911 CommandDestroy::CommandDestroy(TypeOfElem elemType,
1912                                std::string startnode, std::string startport, TypeOfElem startportType,
1913                                std::string endnode, std::string endport, TypeOfElem endportType)
1914   : Command(), _elemType(elemType), _startnode(startnode), _startport(startport),
1915     _endnode(endnode), _endport(endport), _startportType(startportType), _endportType(endportType)
1916 {
1917   DEBTRACE("CommandDestroy::CommandDestroy");
1918   _normalReverse = false;
1919 }
1920
1921 std::string CommandDestroy::dump()
1922 {
1923   string ret ="CommandDestroy " + ProcInvoc::getTypeName(_elemType);
1924   ret += " " + _startnode + " " + _startport;
1925   ret += " " + _endnode + " " + _endport;
1926   return ret;
1927 }
1928
1929 bool CommandDestroy::localExecute()
1930 {
1931   DEBTRACE("CommandDestroy::localExecute");
1932   try
1933     {
1934       Proc* proc = GuiContext::getCurrent()->getProc();
1935       Subject *subject = 0;
1936       Subject *father  = 0;
1937       switch (_elemType)
1938         {
1939         case SALOMEPROC:
1940         case BLOC:
1941         case FOREACHLOOP:
1942         case OPTIMIZERLOOP:
1943         case FORLOOP:
1944         case WHILELOOP:
1945         case SWITCH:
1946         case PYTHONNODE:
1947         case PYFUNCNODE:
1948         case CORBANODE:
1949         case SALOMENODE:
1950         case CPPNODE:
1951         case SALOMEPYTHONNODE:
1952         case XMLNODE:
1953         case SPLITTERNODE:
1954         case DFTODSFORLOOPNODE:
1955         case DSTODFFORLOOPNODE:
1956         case PRESETNODE:
1957         case OUTNODE:
1958         case STUDYINNODE:
1959         case STUDYOUTNODE:
1960           {
1961             Node* node = proc;
1962             if (!_startnode.empty()) node = proc->getChildByName(_startnode);
1963             YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1964             subject = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1965             father  = subject->getParent();
1966           }
1967           break;
1968         case INPUTPORT:
1969           {
1970             Node* node = proc->getChildByName(_startnode);
1971             InPort* inp = node->getInputPort(_startport);
1972             YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
1973             subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
1974             father  = subject->getParent();
1975           }
1976           break;
1977         case INPUTDATASTREAMPORT:
1978           {
1979             Node* node = proc->getChildByName(_startnode);
1980             InPort* inp = node->getInputDataStreamPort(_startport);
1981             YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
1982             subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
1983             father  = subject->getParent();
1984           }
1985           break;
1986         case OUTPUTPORT:
1987           {
1988             Node* node = proc->getChildByName(_startnode);
1989             OutPort* outp = node->getOutputPort(_startport);
1990             YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
1991             subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
1992             father  = subject->getParent();
1993           }
1994           break;
1995         case OUTPUTDATASTREAMPORT:
1996           {
1997             Node* node = proc->getChildByName(_startnode);
1998             OutPort* outp = node->getOutputDataStreamPort(_startport);
1999             YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2000             subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2001             father  = subject->getParent();
2002           }
2003           break;
2004         case DATALINK:
2005           {
2006             Node* outn = proc->getChildByName(_startnode);
2007             Node* inn = proc->getChildByName(_endnode);
2008
2009             OutPort* outp;
2010             InPort* inp;
2011
2012             if(_startportType == OUTPUTPORT)
2013               outp = outn->getOutputPort(_startport);
2014             else
2015               outp = outn->getOutputDataStreamPort(_startport);
2016
2017             if(_endportType == INPUTPORT)
2018               inp = inn->getInputPort(_endport);
2019             else
2020               inp = inn->getInputDataStreamPort(_endport);
2021
2022             pair<OutPort*,InPort*> keymap = pair<OutPort*,InPort*>(outp,inp);
2023             YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(keymap));
2024             subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
2025             father  = subject->getParent();
2026           }
2027           break;
2028         case CONTROLLINK:
2029           {
2030             Node* outn = proc->getChildByName(_startnode);
2031             Node* inn = proc->getChildByName(_endnode);
2032             pair<Node*,Node*> keymap = pair<Node*,Node*>(outn,inn);
2033             YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keymap));
2034             subject = GuiContext::getCurrent()->_mapOfSubjectControlLink[keymap];
2035             father  = subject->getParent();
2036           }
2037           break;
2038         case CONTAINER:
2039           {
2040             Container *container = proc->containerMap[_startnode];
2041             subject = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
2042             break;
2043           }
2044         case COMPONENT:
2045         case REFERENCE:
2046         case DATATYPE:
2047         case UNKNOWN:
2048           throw Exception("Command Destroy not implemented for that type");
2049           break;
2050         }
2051       YASSERT(subject);
2052       Subject::erase(subject);
2053       if (father) 
2054         {
2055           father->select(true);
2056           father->update(REMOVE, 0, 0);
2057         }
2058       subject = 0;
2059       return true; 
2060     }
2061   catch (Exception& ex)
2062     {
2063       DEBTRACE("CommandDestroy::localExecute() : " << ex.what());
2064       setErrorMsg(ex);
2065       return false;
2066     }
2067 }
2068
2069 bool CommandDestroy::localReverse()
2070 {
2071   DEBTRACE("CommandDestroy::localReverse");
2072   //! nothing to do here, all is done in subcommands
2073   return true;
2074 }
2075  
2076 // ----------------------------------------------------------------------------
2077
2078 CommandSetInPortValue::CommandSetInPortValue(std::string node,
2079                                              std::string port,
2080                                              std::string value)
2081   : Command(), _node(node), _port(port), _value(value)
2082 {
2083   DEBTRACE("CommandSetInPortValue::CommandSetInPortValue " << node << " " << port << " " << value);
2084   _oldValue = "";
2085 }
2086
2087 std::string CommandSetInPortValue::dump()
2088 {
2089   string ret ="CommandSetInPortValue " + _node + " " + _port + " " + _value;
2090   return ret;
2091 }
2092     
2093 bool CommandSetInPortValue::localExecute()
2094 {
2095   DEBTRACE("CommandSetInPortValue::localExecute");
2096   InputPort* inp ;
2097   InputPresetPort *inpp = 0;
2098   InputStudyPort *insp = 0;
2099   DataNode *dnode = 0;
2100   SubjectDataPort *sinp = 0;
2101   try
2102     {
2103       Proc* proc = GuiContext::getCurrent()->getProc();
2104       Node* node = proc->getChildByName(_node);
2105       inp = node->getInputPort(_port);
2106       inpp = dynamic_cast<InputPresetPort*>(inp);
2107       insp = dynamic_cast<InputStudyPort*>(inp);
2108       dnode = dynamic_cast<DataNode*>(node);
2109       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2110       sinp = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2111     }
2112   catch (Exception& ex)
2113     {
2114       DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2115       setErrorMsg(ex);
2116       return false;
2117     }
2118
2119   if(insp && dnode)
2120     {
2121       //It's a study port
2122       _oldValue = insp->getAsString();
2123       DEBTRACE("old value="<< _oldValue);
2124       dnode->setData(insp, _value );
2125       sinp->update(SETVALUE, 0, sinp);
2126       return true;
2127     }
2128
2129   PyObject *result;
2130   PyGILState_STATE gstate = PyGILState_Ensure();
2131   try
2132     {
2133       _oldValue = inp->getAsString();
2134       if (_oldValue == "None") _oldValue = "";
2135       DEBTRACE("old value="<< _oldValue);
2136       std::string strval;
2137       if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2138         strval = "\"" + _value + "\"";
2139       else
2140         strval = _value;
2141       result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2142       inp->edInit("Python", result);
2143       Py_DECREF(result);
2144
2145       PyGILState_Release(gstate);
2146       sinp->update(SETVALUE, 0, sinp);
2147       return true;
2148     }
2149   catch (Exception& ex)
2150     {
2151       DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2152       //Py_DECREF(result);
2153       PyGILState_Release(gstate);
2154       setErrorMsg(ex);
2155       return false;
2156     }
2157 }
2158
2159 bool CommandSetInPortValue::localReverse()
2160 {
2161   DEBTRACE("CommandSetInPortValue::localReverse");
2162   InputPort* inp ;
2163   InputPresetPort *inpp = 0;
2164   InputStudyPort *insp = 0;
2165   DataNode *dnode = 0;
2166   SubjectDataPort *sinp = 0;
2167   try
2168     {
2169       Proc* proc = GuiContext::getCurrent()->getProc();
2170       Node* node = proc->getChildByName(_node);
2171       inp = node->getInputPort(_port);
2172       inpp = dynamic_cast<InputPresetPort*>(inp);
2173       insp = dynamic_cast<InputStudyPort*>(inp);
2174       dnode = dynamic_cast<DataNode*>(node);
2175       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2176       sinp = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2177     }
2178   catch (Exception& ex)
2179     {
2180       DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2181       setErrorMsg(ex);
2182       return false;
2183     }
2184
2185   if(insp && dnode)
2186     {
2187       //It's a study port
2188       _value = insp->getAsString();
2189       DEBTRACE("value="<< _value);
2190       DEBTRACE("old value="<< _oldValue);
2191       dnode->setData(insp, _oldValue );
2192       sinp->update(SETVALUE, 0, sinp);
2193       return true;
2194     }
2195
2196   PyObject *result = Py_None;
2197   PyGILState_STATE gstate = PyGILState_Ensure();
2198   try
2199     {
2200       _value = inp->getAsString();
2201       DEBTRACE("value="<< _value);
2202       DEBTRACE("old value="<< _oldValue);
2203       if (!_oldValue.empty())
2204         {
2205           std::string strval;
2206           if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2207             strval = "\"" + _oldValue + "\"";
2208           else
2209             strval = _oldValue;
2210           result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2211         }
2212       inp->edInit("Python", result);
2213       Py_DECREF(result);
2214       PyGILState_Release(gstate);
2215       sinp->update(SETVALUE, 0, sinp);
2216       return true;
2217     }
2218   catch (Exception& ex)
2219     {
2220       DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2221       //Py_DECREF(result);
2222       PyGILState_Release(gstate);
2223       setErrorMsg(ex);
2224       return false;
2225     }
2226 }
2227
2228 // ----------------------------------------------------------------------------
2229
2230 CommandSetOutPortValue::CommandSetOutPortValue(std::string node,
2231                                                std::string port,
2232                                                std::string value)
2233   : Command(), _node(node), _port(port), _value(value)
2234 {
2235   DEBTRACE("CommandSetOutPortValue::CommandSetOutPortValue " << node << " " << port << " " << value);
2236   _oldValue = "";
2237 }
2238  
2239 std::string CommandSetOutPortValue::dump()
2240 {
2241   string ret ="CommandSetOutPortValue " + _node + " " + _port + " " + _value;
2242   return ret;
2243 }
2244    
2245 bool CommandSetOutPortValue::localExecute()
2246 {
2247   DEBTRACE("CommandSetOutPortValue::localExecute");
2248   OutputPresetPort *outpp = 0;
2249   OutputStudyPort *outsp = 0;
2250   DataNode *dnode = 0;
2251   SubjectDataPort *soutp = 0;
2252   try
2253     {
2254       Proc* proc = GuiContext::getCurrent()->getProc();
2255       Node* node = proc->getChildByName(_node);
2256       OutputPort* outp = node->getOutputPort(_port);
2257       outpp = dynamic_cast<OutputPresetPort*>(outp);
2258       outsp = dynamic_cast<OutputStudyPort*>(outp);
2259       dnode = dynamic_cast<DataNode*>(node);
2260       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2261       soutp = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2262     }
2263   catch (Exception& ex)
2264     {
2265       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2266       setErrorMsg(ex);
2267       return false;
2268     }
2269
2270   if (!outpp && !outsp)
2271     {
2272       DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2273       GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2274       return false;
2275     }
2276
2277   if (!dnode)
2278     {
2279       DEBTRACE("Set value on output port only possible on a dataNode");
2280       GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2281       return false;
2282     }
2283
2284   if(outsp)
2285     {
2286       //It's a study port
2287       _oldValue = outsp->getAsString();
2288       DEBTRACE("old value="<< _oldValue);
2289       dnode->setData(outsp, _value );
2290       soutp->update(SETVALUE, 0, soutp);
2291      return true;
2292     }
2293
2294   PyObject *result;
2295   try
2296     {
2297       _oldValue = outpp->getAsString();
2298       if (_oldValue == "None") _oldValue = "";
2299       DEBTRACE("old value="<< _oldValue);
2300       std::string strval;
2301       if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2302         strval = "\"" + _value + "\"";
2303       else
2304         strval = _value;
2305       result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2306     }
2307   catch (Exception& ex)
2308     {
2309       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2310       setErrorMsg(ex);
2311       return false;
2312     }
2313
2314   string val;
2315   PyGILState_STATE gstate = PyGILState_Ensure();
2316   try
2317     {
2318       DEBTRACE(PyObject_Str(result));
2319       val = convertPyObjectXml(outpp->edGetType(), result);
2320       DEBTRACE(val);
2321       dnode->setData(outpp, val );
2322       soutp->update(SETVALUE, 0, soutp);
2323     }
2324   catch (Exception& ex)
2325     {
2326       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2327       setErrorMsg(ex);
2328       Py_DECREF(result);
2329       PyGILState_Release(gstate);
2330       return false;
2331     }
2332
2333   Py_DECREF(result);
2334   PyGILState_Release(gstate);
2335   return true;
2336 }
2337
2338 bool CommandSetOutPortValue::localReverse()
2339 {
2340   DEBTRACE("CommandSetOutPortValue::localReverse");
2341   OutputPresetPort *outpp = 0;
2342   OutputStudyPort *outsp = 0;
2343   DataNode *dnode = 0;
2344   SubjectDataPort *soutp = 0;
2345   try
2346     {
2347       Proc* proc = GuiContext::getCurrent()->getProc();
2348       Node* node = proc->getChildByName(_node);
2349       OutputPort* outp = node->getOutputPort(_port);
2350       outpp = dynamic_cast<OutputPresetPort*>(outp);
2351       outsp = dynamic_cast<OutputStudyPort*>(outp);
2352       dnode = dynamic_cast<DataNode*>(node);
2353       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2354       soutp = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2355     }
2356   catch (Exception& ex)
2357     {
2358       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2359       setErrorMsg(ex);
2360       return false;
2361     }
2362
2363   if (!outpp && !outsp)
2364     {
2365       DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2366       GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2367       return false;
2368     }
2369
2370   if (!dnode)
2371     {
2372       DEBTRACE("Set value on output port only possible on a dataNode");
2373       GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2374       return false;
2375     }
2376
2377   if(outsp)
2378     {
2379       //It's a study port
2380       _value = outsp->getAsString();
2381       DEBTRACE("value="<< _value);
2382       DEBTRACE("old value="<< _oldValue);
2383       dnode->setData(outsp, _oldValue );
2384       soutp->update(SETVALUE, 0, soutp);
2385       return true;
2386     }
2387
2388   PyObject *result = Py_None;
2389   try
2390     {
2391       _value = outpp->getAsString();
2392       DEBTRACE("value="<< _value);
2393       DEBTRACE("old value="<< _oldValue);
2394       if (!_oldValue.empty())
2395         {
2396           std::string strval;
2397           if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2398             strval = "\"" + _value + "\"";
2399           else
2400             strval = _value;
2401           result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2402         }
2403     }
2404   catch (Exception& ex)
2405     {
2406       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2407       setErrorMsg(ex);
2408       return false;
2409     }
2410
2411   string val;
2412   PyGILState_STATE gstate = PyGILState_Ensure();
2413   try
2414     {
2415       DEBTRACE(PyObject_Str(result));
2416       val = convertPyObjectXml(outpp->edGetType(), result);
2417       DEBTRACE(val);
2418       dnode->setData(outpp, val );
2419       soutp->update(SETVALUE, 0, soutp);
2420     }
2421   catch (Exception& ex)
2422     {
2423       DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2424       setErrorMsg(ex);
2425       Py_DECREF(result);
2426       PyGILState_Release(gstate);
2427       return false;
2428     }
2429
2430   Py_DECREF(result);
2431   PyGILState_Release(gstate);
2432   return true;
2433 }
2434  
2435 // ----------------------------------------------------------------------------
2436
2437 CommandSetSwitchSelect::CommandSetSwitchSelect(std::string aSwitch,
2438                                                std::string value)
2439   : Command(), _switch(aSwitch), _value(value)
2440 {
2441   DEBTRACE("CommandSetSwitchSelect::CommandSetSwitchSelect");
2442   _oldValue = "0";
2443 }
2444
2445 std::string CommandSetSwitchSelect::dump()
2446 {
2447   string ret ="CommandSetSwitchSelect " + _switch + " " + _value;
2448   return ret;
2449 }
2450     
2451 bool CommandSetSwitchSelect::localExecute()
2452 {
2453   DEBTRACE("CommandSetSwitchSelect::localExecute");
2454   try
2455     {
2456       Proc* proc = GuiContext::getCurrent()->getProc();
2457       Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2458       InputPort *condPort = aSwitch->edGetConditionPort();
2459       _oldValue = condPort->getAsString();
2460       if (_oldValue == "None") _oldValue = "0";
2461       int val = atoi(_value.c_str());
2462       condPort->edInit(val);
2463       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2464       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2465       snode->update(SETSELECT, 0, snode);
2466     }
2467   catch (Exception& ex)
2468     {
2469       DEBTRACE("CommandSetSwitchSelect::localExecute() : " << ex.what());
2470       setErrorMsg(ex);
2471       return false;
2472     }
2473 }
2474
2475 bool CommandSetSwitchSelect::localReverse()
2476 {
2477   DEBTRACE("CommandSetSwitchSelect::localReverse");
2478   try
2479     {
2480       Proc* proc = GuiContext::getCurrent()->getProc();
2481       Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2482       InputPort *condPort = aSwitch->edGetConditionPort();
2483       int val = atoi(_oldValue.c_str());
2484       condPort->edInit(val);
2485       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2486       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2487       snode->update(SETSELECT, 0, snode);
2488     }
2489   catch (Exception& ex)
2490     {
2491       DEBTRACE("CommandSetSwitchSelect::localReverse() : " << ex.what());
2492       setErrorMsg(ex);
2493       return false;
2494     }
2495 }
2496
2497 // ----------------------------------------------------------------------------
2498
2499 CommandSetSwitchCase::CommandSetSwitchCase(std::string aSwitch,
2500                                            std::string node,
2501                                            std::string value)
2502   : Command(), _switch(aSwitch), _node(node), _value(value)
2503 {
2504   DEBTRACE("CommandSetSwitchCase::CommandSetSwitchCase");
2505   _oldValue = 0;
2506   _oldNode = "";
2507 }
2508
2509 std::string CommandSetSwitchCase::dump()
2510 {
2511   string ret ="CommandSetSwitchCase " + _switch + " " + _node + " " + _value;
2512   return ret;
2513 }
2514
2515 bool CommandSetSwitchCase::localExecute()
2516 {
2517   DEBTRACE("CommandSetSwitchCase::localExecute");
2518   try
2519     {
2520       DEBTRACE("CommandSetSwitchCase::localExecute");
2521       Proc* proc = GuiContext::getCurrent()->getProc();
2522       Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2523       Node* node = proc->getChildByName(_node);
2524       int val = atoi(_value.c_str());
2525       if (aSwitch->edGetNode(val))
2526         {
2527           throw YACS::Exception("Set Switch Case impossible: value already used");
2528         }
2529       int oldVal = aSwitch->getRankOfNode(node);
2530       aSwitch->edChangeCase(oldVal,val);
2531       _oldValue = oldVal;
2532       _oldNode = proc->getChildName(node);
2533       DEBTRACE("CommandSetSwitchCase::localExecute OK " << val);
2534       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2535       SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2536       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2537       ssw->update(SETCASE, val, snode);
2538       snode->recursiveUpdate(RENAME, 0, snode);
2539       return true;
2540     }
2541   catch (Exception& ex)
2542     {
2543       DEBTRACE("CommandSetSwitchCase::localExecute() : " << ex.what());
2544       setErrorMsg(ex);
2545       return false;
2546     }
2547 }
2548
2549 bool CommandSetSwitchCase::localReverse()
2550 {
2551   DEBTRACE("CommandSetSwitchCase::localReverse");
2552   try
2553     {
2554       DEBTRACE("CommandSetSwitchCase::localReverse");
2555       Proc* proc = GuiContext::getCurrent()->getProc();
2556       Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2557       Node* node = proc->getChildByName(_oldNode);
2558       int val = _oldValue;
2559       if (aSwitch->edGetNode(val))
2560         {
2561           throw YACS::Exception("Set Switch Case impossible: value already used");
2562         }
2563       int oldVal = aSwitch->getRankOfNode(node);
2564       aSwitch->edChangeCase(oldVal,val);
2565       DEBTRACE("CommandSetSwitchCase::localReverse OK " << val);
2566       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2567       SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2568       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2569       ssw->update(SETCASE, val, snode);
2570       snode->recursiveUpdate(RENAME, 0, snode);
2571       return true;
2572     }
2573   catch (Exception& ex)
2574     {
2575       DEBTRACE("CommandSetSwitchCase::localReverse() : " << ex.what());
2576       setErrorMsg(ex);
2577       return false;
2578     }
2579 }
2580
2581 // ----------------------------------------------------------------------------
2582
2583 CommandSetForLoopSteps::CommandSetForLoopSteps(std::string forLoop,
2584                                                std::string value)
2585   : Command(), _forLoop(forLoop), _value(value)
2586 {
2587   DEBTRACE("CommandSetForLoopSteps::CommandSetForLoopSteps");
2588   _oldValue = 0;
2589 }
2590
2591
2592 std::string CommandSetForLoopSteps::dump()
2593 {
2594   string ret ="CommandSetForLoopSteps " + _forLoop + " " + _value;
2595   return ret;
2596 }
2597     
2598 bool CommandSetForLoopSteps::localExecute()
2599 {
2600   DEBTRACE("CommandSetForLoopSteps::localExecute");
2601   try
2602     {
2603       DEBTRACE("CommandSetForLoopSteps::localExecute");
2604       Proc* proc = GuiContext::getCurrent()->getProc();
2605       ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2606       InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2607       _oldValue = atoi(forLoop->edGetNbOfTimesInputPort()->getAsString().c_str());
2608       int val = atoi(_value.c_str());
2609       nbSteps->edInit(val);
2610       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2611       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2612       snode->update(SETVALUE, 0, snode);
2613       return true;
2614     }
2615   catch (Exception& ex)
2616     {
2617       DEBTRACE("CommandSetForLoopSteps::localExecute() : " << ex.what());
2618       setErrorMsg(ex);
2619       return false;
2620     }
2621 }
2622
2623 bool CommandSetForLoopSteps::localReverse()
2624 {
2625   DEBTRACE("CommandSetForLoopSteps::localReverse");
2626   try
2627     {
2628       DEBTRACE("CommandSetForLoopSteps::localReverse");
2629       Proc* proc = GuiContext::getCurrent()->getProc();
2630       ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2631       InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2632       nbSteps->edInit(_oldValue);
2633       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2634       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2635       snode->update(SETVALUE, 0, snode);
2636       return true;
2637     }
2638   catch (Exception& ex)
2639     {
2640       DEBTRACE("CommandSetForLoopSteps::localReverse() : " << ex.what());
2641       setErrorMsg(ex);
2642       return false;
2643     }
2644 }
2645
2646 // ----------------------------------------------------------------------------
2647
2648 CommandSetWhileCondition::CommandSetWhileCondition(std::string whileLoop,
2649                                                    std::string value)
2650   : Command(), _whileLoop(whileLoop), _value(value)
2651 {
2652   DEBTRACE("CommandSetWhileCondition::CommandSetWhileCondition");
2653   _oldValue = 0;
2654 }
2655
2656 std::string CommandSetWhileCondition::dump()
2657 {
2658   string ret ="CommandSetWhileCondition " + _whileLoop + " " + _value;
2659   return ret;
2660 }
2661
2662 bool CommandSetWhileCondition::localExecute()
2663 {
2664   DEBTRACE("CommandSetWhileCondition::localExecute");
2665   try
2666     {
2667       Proc* proc = GuiContext::getCurrent()->getProc();
2668       WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2669       InputPort *cond = whileLoop->edGetConditionPort();
2670       _oldValue = atoi(whileLoop->edGetConditionPort()->getAsString().c_str());
2671       bool val = atoi(_value.c_str());
2672       cond->edInit(val);
2673       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2674       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2675       snode->update(SETVALUE, 0, snode);
2676       return true;
2677     }
2678   catch (Exception& ex)
2679     {
2680       DEBTRACE("CommandSetWhileCondition::localExecute() : " << ex.what());
2681       setErrorMsg(ex);
2682       return false;
2683     }
2684 }
2685
2686 bool CommandSetWhileCondition::localReverse()
2687 {
2688   DEBTRACE("CommandSetWhileCondition::localReverse");
2689   try
2690     {
2691       Proc* proc = GuiContext::getCurrent()->getProc();
2692       WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2693       InputPort *cond = whileLoop->edGetConditionPort();
2694       cond->edInit(_oldValue);
2695       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2696       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2697       snode->update(SETVALUE, 0, snode);
2698       return true;
2699     }
2700   catch (Exception& ex)
2701     {
2702       DEBTRACE("CommandSetWhileCondition::localReverse() : " << ex.what());
2703       setErrorMsg(ex);
2704       return false;
2705     }
2706 }
2707
2708 // ----------------------------------------------------------------------------
2709
2710 CommandSetForEachBranch::CommandSetForEachBranch(std::string forEach,
2711                                                  std::string value)
2712   : Command(), _forEach(forEach), _value(value)
2713 {
2714   DEBTRACE("CommandSetForEachBranch::CommandSetForEachBranch");
2715   _oldValue = 0;
2716 }
2717  
2718 std::string CommandSetForEachBranch::dump()
2719 {
2720   string ret ="CommandSetForEachBranch " + _forEach + " " + _value;
2721   return ret;
2722 }
2723    
2724 bool CommandSetForEachBranch::localExecute()
2725 {
2726   DEBTRACE("CommandSetForEachBranch::localExecute");
2727   try
2728     {
2729       Proc* proc = GuiContext::getCurrent()->getProc();
2730       Node* node=proc->getChildByName(_forEach);
2731       InputPort *nbBranches = node->getInputPort("nbBranches");
2732       _oldValue = atoi(nbBranches->getAsString().c_str());
2733       int val = atoi(_value.c_str());
2734       nbBranches->edInit(val);
2735       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2736       SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2737       spo->update(SETVALUE, 0, spo);
2738       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2739       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2740       snode->update(SETVALUE, 0, snode);
2741       return true;
2742     }
2743   catch (Exception& ex)
2744     {
2745       DEBTRACE("CommandSetForEachBranch::localExecute() : " << ex.what());
2746       setErrorMsg(ex);
2747       return false;
2748     }
2749 }
2750
2751 bool CommandSetForEachBranch::localReverse()
2752 {
2753   DEBTRACE("CommandSetForEachBranch::localReverse");
2754   try
2755     {
2756       Proc* proc = GuiContext::getCurrent()->getProc();
2757       Node* node=proc->getChildByName(_forEach);
2758       InputPort *nbBranches = node->getInputPort("nbBranches");
2759       nbBranches->edInit(_oldValue);
2760       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2761       SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2762       spo->update(SETVALUE, 0, spo);
2763       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2764       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2765       snode->update(SETVALUE, 0, snode);
2766       return true;
2767     }
2768   catch (Exception& ex)
2769     {
2770       DEBTRACE("CommandSetForEachBranch::localReverse() : " << ex.what());
2771       setErrorMsg(ex);
2772       return false;
2773     }
2774 }
2775
2776 // ----------------------------------------------------------------------------
2777
2778 CommandSetAlgo::CommandSetAlgo(std::string optimizer, std::string alglib, std::string symbol)
2779   : Command(), _optimizer(optimizer), _alglib(alglib), _symbol(symbol)
2780 {
2781   DEBTRACE("CommandSetAlgo::CommandSetAlgo" << _optimizer << " " << _alglib << " " << _symbol);
2782   _oldAlglib = "";
2783   _oldSymbol = "";
2784 }
2785
2786 std::string CommandSetAlgo::dump()
2787 {
2788   string ret ="CommandSetAlgo " + _optimizer + " " + _alglib + " " + _symbol;
2789   return ret;
2790 }
2791
2792 bool CommandSetAlgo::localExecute()
2793 {
2794   DEBTRACE("CommandSetAlgo::localExecute");
2795   try
2796     {
2797       Proc* proc = GuiContext::getCurrent()->getProc();
2798       OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2799       loop->setAlgorithm(_alglib,_symbol);
2800       _oldAlglib = _alglib;
2801       _oldSymbol = _symbol;
2802       InputPort *port = loop->edGetPortForOutPool();
2803       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2804       SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2805       spo->update(UPDATE, 0, spo);
2806       OutputPort *oport = loop->edGetSamplePort();
2807       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2808       spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2809       spo->update(UPDATE, 0, spo);
2810       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2811       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2812       snode->update(SETVALUE, 0, snode);
2813       return true;
2814     }
2815   catch (Exception& ex)
2816     {
2817       DEBTRACE("CommandSetAlgo::localExecute() : " << ex.what());
2818       setErrorMsg(ex);
2819       return false;
2820     }
2821 }
2822
2823 bool CommandSetAlgo::localReverse()
2824 {
2825   DEBTRACE("CommandSetAlgo::localReverse");
2826   try
2827     {
2828       Proc* proc = GuiContext::getCurrent()->getProc();
2829       OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2830       loop->setAlgorithm(_oldAlglib,_oldSymbol);
2831       InputPort *port = loop->edGetPortForOutPool();
2832       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2833       SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2834       spo->update(UPDATE, 0, spo);
2835       OutputPort *oport = loop->edGetSamplePort();
2836       YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2837       spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2838       spo->update(UPDATE, 0, spo);
2839       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2840       SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2841       snode->update(SETVALUE, 0, snode);
2842       return true;
2843     }
2844   catch (Exception& ex)
2845     {
2846       DEBTRACE("CommandSetAlgo::localReverse() : " << ex.what());
2847       setErrorMsg(ex);
2848       return false;
2849     }
2850   return true;
2851 }
2852
2853 // ----------------------------------------------------------------------------
2854
2855 CommandAddLink::CommandAddLink(std::string outNode, std::string outPort, TypeOfElem outPortType,
2856                                std::string inNode, std::string inPort, TypeOfElem inPortType, bool control)
2857   : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2858                _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2859 {
2860   DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2861   _controlCreatedWithDF = false;
2862 }
2863
2864 std::string CommandAddLink::dump()
2865 {
2866   string s = "false";
2867   if (_control) s = "true";
2868   string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2869   return ret;
2870 }
2871
2872 bool CommandAddLink::localExecute()
2873 {
2874   DEBTRACE("CommandAddLink::localExecute");
2875   DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2876   try
2877     {
2878       Proc* proc = GuiContext::getCurrent()->getProc();
2879       Node* outn = proc->getChildByName(_outNode);
2880       Node* inn = proc->getChildByName(_inNode);
2881       OutPort* outp;
2882       InPort* inp;
2883
2884       // --- is a control link already existing ?
2885       bool preexistingControl = false;
2886       {
2887         Node* outn2=outn;
2888         Node* inn2=inn;
2889         ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2890         if(outn2==father || inn2==father)
2891           preexistingControl = true;
2892         else
2893           {
2894             while(outn2->getFather() != father)
2895               outn2 = outn2->getFather();
2896             while(inn2->getFather() != father)
2897               inn2 = inn2->getFather();
2898             OutGate *ogate = outn2->getOutGate();
2899             InGate *igate = inn2->getInGate();
2900             if (ogate->isAlreadyInSet(igate))
2901               preexistingControl = true;
2902           }
2903       }
2904
2905       if(_outPortType == OUTPUTPORT)
2906         outp = outn->getOutputPort(_outPort);
2907       else
2908         outp = outn->getOutputDataStreamPort(_outPort);
2909
2910       if(_inPortType == INPUTPORT)
2911         inp = inn->getInputPort(_inPort);
2912       else
2913         inp = inn->getInputDataStreamPort(_inPort);
2914
2915       ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2916       DEBTRACE(cla->getName());
2917       if (dynamic_cast<OutputDataStreamPort*>(outp))
2918         cla->edAddLink(outp,inp);
2919       else if(_control)
2920         cla->edAddDFLink(outp,inp);
2921       else
2922         cla->edAddLink(outp,inp);
2923
2924       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2925       SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
2926       SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2927       DEBTRACE(scla->getName());
2928       SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2929       SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2930       SubjectDataPort *subOutport = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2931       SubjectDataPort *subInport = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2932       SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2933
2934       // --- if control link, identify the nodes linked and draw the control link if not already existing
2935
2936       if (_control)
2937         {
2938           ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2939           if(outn==father || inn==father) return true;
2940           while(outn->getFather() != father)
2941             outn = outn->getFather();
2942           while(inn->getFather() != father)
2943             inn = inn->getFather();
2944           OutGate *ogate = outn->getOutGate();
2945           InGate *igate = inn->getInGate();
2946           if (ogate->isAlreadyInSet(igate))
2947             {
2948               if (!preexistingControl)
2949                 _controlCreatedWithDF = true;
2950               pair<Node*,Node*> keyLink(outn,inn);
2951               if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2952                 {
2953                   SubjectNode *sfno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2954                   SubjectNode *sfni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2955                   if (!sfno || !sfni) return true;
2956                   SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2957                 }
2958             }
2959         }
2960       return true;
2961     }
2962   catch (Exception& ex)
2963     {
2964       DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2965       setErrorMsg(ex);
2966       return false;
2967     }
2968 }
2969
2970 bool CommandAddLink::localReverse()
2971 {
2972   DEBTRACE("CommandAddLink::localReverse");
2973   try
2974     {
2975       SubjectLink *slink =0;
2976       SubjectControlLink *sclink = 0;
2977       Proc* proc = GuiContext::getCurrent()->getProc();
2978       Node* outn = proc->getChildByName(_outNode);
2979       Node* inn = proc->getChildByName(_inNode);
2980       OutPort* outp;
2981       InPort* inp;
2982       if(_outPortType == OUTPUTPORT)
2983         outp = outn->getOutputPort(_outPort);
2984       else
2985         outp = outn->getOutputDataStreamPort(_outPort);
2986       if(_inPortType == INPUTPORT)
2987         inp = inn->getInputPort(_inPort);
2988       else
2989         inp = inn->getInputDataStreamPort(_inPort);
2990       YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(pair<OutPort*,InPort*>(outp,inp)));
2991       slink = GuiContext::getCurrent()->_mapOfSubjectLink[pair<OutPort*,InPort*>(outp,inp)];
2992       if (_controlCreatedWithDF)
2993         {
2994           YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
2995           sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];         
2996         }
2997
2998       Subject *father = slink->getParent();
2999       Subject::erase(slink);
3000       slink = 0;
3001       if (father)
3002         {
3003           DEBTRACE("REMOVE");
3004           father->select(true);
3005           father->update(REMOVE,0,0);
3006         }
3007       if (!sclink)
3008         return true;
3009       father=sclink->getParent();
3010       Subject::erase(sclink);
3011       sclink = 0;
3012       if (father)
3013         {
3014           DEBTRACE("REMOVE");
3015           father->select(true);
3016           father->update(REMOVE,0,0);
3017         }
3018       return true;
3019     }
3020   catch (Exception& ex)
3021     {
3022       DEBTRACE("CommandAddLink::localReverse(): " << ex.what());
3023       setErrorMsg(ex);
3024       return false;
3025     }
3026 }
3027
3028 // ----------------------------------------------------------------------------
3029
3030 CommandAddControlLink::CommandAddControlLink(std::string outNode, std::string inNode)
3031   : Command(), _outNode(outNode), _inNode(inNode)
3032 {
3033   DEBTRACE("CommandAddControlLink::CommandAddControlLink "<<outNode<<"-->>"<<inNode);
3034 }
3035
3036 std::string CommandAddControlLink::dump()
3037 {
3038   string ret ="CommandAddControlLink " + _outNode + " " + _inNode;
3039   return ret;
3040 }
3041
3042 bool CommandAddControlLink::localExecute()
3043 {
3044   DEBTRACE("CommandAddControlLink::localExecute");
3045   try
3046     {
3047       Proc* proc = GuiContext::getCurrent()->getProc();
3048       Node* outn = proc;
3049       if (! _outNode.empty())
3050         outn = proc->getChildByName(_outNode);
3051       Node* inn = proc;
3052       if (! _inNode.empty())
3053         inn = proc->getChildByName(_inNode);
3054       ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn,inn);
3055       DEBTRACE(cla->getName());
3056       bool ret= cla->edAddCFLink(outn,inn);
3057       if(ret==false)
3058         GuiContext::getCurrent()->_lastErrorMessage = "Link already exists";
3059
3060       cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),
3061                                                   inn->getFather());
3062       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
3063       SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
3064       SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
3065       DEBTRACE(scla->getName());
3066       SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
3067       SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
3068       SubjectControlLink *sclink = scla->addSubjectControlLink(sno,sni);
3069       return ret;
3070     }
3071   catch (Exception& ex)
3072     {
3073       DEBTRACE("CommandAddControlLink::localExecute() : " << ex.what());
3074       setErrorMsg(ex);
3075       return false;
3076     }
3077 }
3078
3079 bool CommandAddControlLink::localReverse()
3080 {
3081   DEBTRACE("CommandAddControlLink::localReverse");
3082   try
3083     {
3084       SubjectControlLink *sclink = 0;
3085       Proc* proc = GuiContext::getCurrent()->getProc();
3086       Node* outn = proc->getChildByName(_outNode);
3087       Node* inn = proc->getChildByName(_inNode);
3088       YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
3089       sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];         
3090
3091       Subject *father=sclink->getParent();
3092       Subject::erase(sclink);
3093       sclink = 0;
3094       if (father)
3095         {
3096           DEBTRACE("REMOVE");
3097           father->select(true);
3098           father->update(REMOVE,0,0);
3099         }
3100       return true;
3101     }
3102   catch (Exception& ex)
3103     {
3104       DEBTRACE("CommandAddControlLink::localReverse(): " << ex.what());
3105       setErrorMsg(ex);
3106       return false;
3107     }
3108 }
3109
3110 // ----------------------------------------------------------------------------
3111
3112 CommandAddContainerBase::CommandAddContainerBase(std::string name, std::string refContainer)
3113   : Command(), _name(name), _containerToClone(refContainer), _subcont(0)
3114 {
3115   DEBTRACE("CommandAddContainerBase::CommandAddContainerBase " << name << " " << refContainer);
3116 }
3117
3118 CommandAddContainerBase::~CommandAddContainerBase()
3119 {
3120 }
3121
3122 bool CommandAddContainerBase::localExecute()
3123 {
3124   DEBTRACE("CommandAddContainerBase::localExecute");
3125   try
3126     {
3127       Proc* proc = GuiContext::getCurrent()->getProc();
3128       if (proc->containerMap.count(_name))
3129         {
3130           GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
3131           return false;
3132         }
3133       Container *container(createNewInstance());
3134       if (! _containerToClone.empty())
3135         {
3136           if (proc->containerMap.count(_containerToClone))
3137             {
3138               Container *ref = proc->containerMap[_containerToClone];
3139               YASSERT(ref);
3140               container->setProperties(ref->getProperties());
3141             }
3142           else
3143             {
3144               GuiContext::getCurrent()->_lastErrorMessage = "There is no reference container to clone properties";
3145               return false;
3146             }
3147         }
3148       container->setName(_name);
3149       container->setProc(proc);
3150       proc->containerMap[_name] = container;
3151
3152       SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3153       _subcont = sproc->addSubjectContainer(container, _name);
3154       return true;
3155     }
3156   catch (Exception& ex)
3157     {
3158       DEBTRACE("CommandAddContainerBase::localExecute() : " << ex.what());
3159       setErrorMsg(ex);
3160       return false;
3161     }
3162 }
3163
3164 bool CommandAddContainerBase::localReverse()
3165 {
3166   DEBTRACE("CommandAddContainerBase::localReverse");
3167   try
3168     {
3169       Proc* proc = GuiContext::getCurrent()->getProc();
3170       YASSERT(proc->containerMap.count(_name));
3171       Container *container = proc->containerMap[_name];
3172       YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
3173       _subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
3174       YASSERT(!_subcont->isUsed());
3175       SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3176       sproc->removeSubjectContainer(_subcont);
3177       return true;
3178     }
3179   catch (Exception& ex)
3180     {
3181       DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
3182       setErrorMsg(ex);
3183       return false;
3184     }
3185 }
3186
3187 // ----------------------------------------------------------------------------
3188
3189 CommandAddContainer::CommandAddContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3190 {
3191 }
3192
3193 std::string CommandAddContainer::dump()
3194 {
3195   string ret ="CommandAddContainer " + _name + " " + _containerToClone;
3196   return ret;
3197 }
3198
3199 Container *CommandAddContainer::createNewInstance() const
3200 {
3201   return new SalomeContainer;
3202 }
3203
3204 // ----------------------------------------------------------------------------
3205
3206 CommandAddHPContainer::CommandAddHPContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3207 {
3208 }
3209
3210 std::string CommandAddHPContainer::dump()
3211 {
3212   string ret ="CommandAddHPContainer " + _name + " " + _containerToClone;
3213   return ret;
3214 }
3215
3216 Container *CommandAddHPContainer::createNewInstance() const
3217 {
3218   return new SalomeHPContainer;
3219 }
3220
3221 // ----------------------------------------------------------------------------
3222
3223 CommandSetNodeProperties::CommandSetNodeProperties(std::string position, std::map<std::string,std::string> properties)
3224   : Command(), _position(position), _properties(properties)
3225 {
3226   DEBTRACE("CommandSetNodeProperties::CommandSetNodeProperties " << position);
3227   _oldProp.clear();
3228 }
3229
3230 std::string CommandSetNodeProperties::dump()
3231 {
3232   string ret ="CommandSetNodeProperties " + _position;
3233   return ret;
3234 }
3235
3236 bool CommandSetNodeProperties::localExecute()
3237 {
3238   DEBTRACE("CommandSetNodeProperties::localExecute");
3239   try
3240     {
3241       Proc* proc = GuiContext::getCurrent()->getProc();
3242       Node* node = proc;
3243
3244       if (!_position.empty()) node = proc->getChildByName(_position);
3245
3246       if (node)
3247         {
3248           _oldProp = node->getPropertyMap();
3249           node->setProperties(_properties);
3250           SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3251           snode->update(SETVALUE, 0, snode);
3252           return true;
3253         }
3254       GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3255       return false;
3256     }
3257   catch (Exception& ex)
3258     {
3259       DEBTRACE("CommandSetNodeProperties::localExecute() : " << ex.what());
3260       setErrorMsg(ex);
3261       return false;
3262     }
3263 }
3264
3265 bool CommandSetNodeProperties::localReverse()
3266 {
3267   DEBTRACE("CommandSetNodeProperties::localReverse");
3268   try
3269     {
3270       Proc* proc = GuiContext::getCurrent()->getProc();
3271       Node* node = proc;
3272
3273       if (!_position.empty()) node = proc->getChildByName(_position);
3274
3275       if (node)
3276         {
3277           node->setProperties(_oldProp);
3278           SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3279           snode->update(SETVALUE, 0, snode);
3280           return true;
3281         }
3282       GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3283       return false;
3284     }
3285   catch (Exception& ex)
3286     {
3287       DEBTRACE("CommandSetNodeProperties::localReverse() : " << ex.what());
3288       setErrorMsg(ex);
3289       return false;
3290     }
3291 }
3292
3293 // ----------------------------------------------------------------------------
3294
3295 CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties(std::string compoinstance,
3296                                                                              std::map<std::string,std::string> properties)
3297   : Command(), _compoinstance(compoinstance), _properties(properties)
3298 {
3299   DEBTRACE("CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties " << compoinstance);
3300   _oldProp.clear();
3301 }
3302
3303 std::string CommandSetComponentInstanceProperties::dump()
3304 {
3305   string ret ="CommandSetComponentInstanceProperties " + _compoinstance;
3306   return ret;
3307 }
3308
3309 bool CommandSetComponentInstanceProperties::localExecute()
3310 {
3311   DEBTRACE("CommandSetComponentInstanceProperties::localExecute");
3312   try
3313     {
3314       Proc* proc = GuiContext::getCurrent()->getProc();
3315       if (proc->componentInstanceMap.count(_compoinstance))
3316         {
3317           ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3318           YASSERT(ref);
3319           _oldProp = ref->getProperties();
3320           _oldAnon = ref->isAnonymous();
3321           ref->setProperties(_properties);
3322           ref->setAnonymous(false);
3323           SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3324           subcompo->update(SETVALUE, 0, subcompo);
3325           return true;
3326         }
3327       GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3328       return false;
3329     }
3330   catch (Exception& ex)
3331     {
3332       DEBTRACE("CommandSetComponentInstanceProperties::localExecute() : " << ex.what());
3333       setErrorMsg(ex);
3334       return false;
3335     }
3336 }
3337
3338 bool CommandSetComponentInstanceProperties::localReverse()
3339 {
3340   DEBTRACE("CommandSetComponentInstanceProperties::localReverse");
3341   try
3342     {
3343       Proc* proc = GuiContext::getCurrent()->getProc();
3344       if (proc->componentInstanceMap.count(_compoinstance))
3345         {
3346           ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3347           YASSERT(ref);
3348           ref->setProperties(_oldProp);
3349           ref->setAnonymous(_oldAnon);
3350           SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3351           subcompo->update(SETVALUE, 0, subcompo);
3352           return true;
3353         }
3354       GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3355       return false;
3356     }
3357   catch (Exception& ex)
3358     {
3359       DEBTRACE("CommandSetComponentInstanceProperties::localReverse() : " << ex.what());
3360       setErrorMsg(ex);
3361       return false;
3362     }
3363 }
3364
3365 // ----------------------------------------------------------------------------
3366
3367 CommandSetContainerProperties::CommandSetContainerProperties(std::string container,
3368                                                              std::map<std::string,std::string> properties)
3369   : Command(), _container(container), _properties(properties)
3370 {
3371   DEBTRACE("CommandSetContainerProperties::CommandSetContainerProperties " << container);
3372   _oldProp.clear();
3373 }
3374
3375 std::string CommandSetContainerProperties::dump()
3376 {
3377   string ret ="CommandSetContainerProperties " + _container;
3378   return ret;
3379 }
3380
3381 bool CommandSetContainerProperties::localExecute()
3382 {
3383   DEBTRACE("CommandSetContainerProperties::localExecute");
3384   try
3385     {
3386       Proc* proc = GuiContext::getCurrent()->getProc();
3387       if (proc->containerMap.count(_container))
3388         {
3389           Container *ref(proc->containerMap[_container]);
3390           YASSERT(ref);
3391           _oldProp = ref->getProperties();
3392           ref->setProperties(_properties);
3393           SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[ref]);
3394           scont->update(UPDATE, 0, scont);
3395           scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
3396           return true;
3397         }
3398       GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3399       return false;
3400     }
3401   catch (Exception& ex)
3402     {
3403       DEBTRACE("CommandSetContainerProperties::localExecute() : " << ex.what());
3404       setErrorMsg(ex);
3405       return false;
3406     }
3407 }
3408
3409 bool CommandSetContainerProperties::localReverse()
3410 {
3411   DEBTRACE("CommandSetContainerProperties::localReverse");
3412   try
3413     {
3414       Proc* proc = GuiContext::getCurrent()->getProc();
3415       if (proc->containerMap.count(_container))
3416         {
3417           Container *ref = proc->containerMap[_container];
3418           YASSERT(ref);
3419           ref->setProperties(_oldProp);
3420           return true;
3421         }
3422       GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3423       return false;
3424     }
3425   catch (Exception& ex)
3426     {
3427       DEBTRACE("CommandSetContainerProperties::localReverse() : " << ex.what());
3428       setErrorMsg(ex);
3429       return false;
3430     }
3431 }
3432
3433 // ----------------------------------------------------------------------------
3434
3435 CommandSetDSPortProperties::CommandSetDSPortProperties(std::string node, std::string port, bool isInport,
3436                                                        std::map<std::string,std::string> properties)
3437   : Command(), _nodeName(node), _portName(port), _isInport(isInport), _properties(properties)
3438 {
3439   DEBTRACE("CommandSetDSPortProperties::CommandSetDSPortProperties " << node << "." << port << " " << isInport);
3440   _oldProp.clear();
3441 }
3442       
3443 std::string CommandSetDSPortProperties::dump()
3444 {
3445   string s = "false";
3446   if (_isInport) s = "true";
3447   string ret ="CommandSetDSPortProperties " + _nodeName + " " + _portName + " " + s;
3448   return ret;
3449 }
3450
3451 bool CommandSetDSPortProperties::localExecute()
3452 {
3453   DEBTRACE("CommandSetDSPortProperties::localExecute");
3454   try
3455     {
3456       Proc* proc = GuiContext::getCurrent()->getProc();
3457       Node* node = proc->getChildByName(_nodeName);
3458       DataStreamPort* DSPort = 0;
3459       if (_isInport)
3460         DSPort = node->getInputDataStreamPort(_portName);
3461       else
3462         DSPort = node->getOutputDataStreamPort(_portName);
3463       _oldProp = DSPort->getProperties();
3464       DSPort->setProperties(_properties);
3465       return true;
3466     }
3467   catch (Exception& ex)
3468     {
3469       DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3470       setErrorMsg(ex);
3471       return false;
3472     }
3473 }
3474       
3475 bool CommandSetDSPortProperties::localReverse()
3476 {
3477   DEBTRACE("CommandSetDSPortProperties::localReverse");
3478   try
3479     {
3480       Proc* proc = GuiContext::getCurrent()->getProc();
3481       Node* node = proc->getChildByName(_nodeName);
3482       DataStreamPort* DSPort = 0;
3483       if (_isInport)
3484         DSPort = node->getInputDataStreamPort(_portName);
3485       else
3486         DSPort = node->getOutputDataStreamPort(_portName);
3487       DSPort->setProperties(_oldProp);
3488       return true;
3489     }
3490   catch (Exception& ex)
3491     {
3492       DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3493       setErrorMsg(ex);
3494       return false;
3495     }
3496 }
3497
3498 // ----------------------------------------------------------------------------
3499
3500 CommandSetLinkProperties::CommandSetLinkProperties(std::string startnode, std::string startport, 
3501                                                    std::string endnode, std::string endport,
3502                                                    std::map<std::string,std::string> properties)
3503   : Command(), _startNodeName(startnode), _startPortName(startport), 
3504     _endNodeName(endnode), _endPortName(endport),
3505     _properties(properties)
3506 {
3507   DEBTRACE("CommandSetLinkProperties::CommandSetLinkProperties " );
3508   _oldProp.clear();
3509 }
3510
3511 std::string CommandSetLinkProperties::dump()
3512 {
3513   string ret ="CommandSetLinkProperties " + _startNodeName + " " + _startPortName + " " + _endNodeName + " " + _endPortName;
3514   return ret;
3515 }
3516
3517 bool CommandSetLinkProperties::localExecute()
3518 {
3519   DEBTRACE("CommandSetLinkProperties::localExecute");
3520   try
3521     {
3522       Proc* proc = GuiContext::getCurrent()->getProc();
3523       Node* node;
3524       InputDataStreamPort* inDSPort = 0;
3525       OutputDataStreamPort* outDSPort = 0;
3526
3527       node   = proc->getChildByName(_startNodeName);
3528       outDSPort = node->getOutputDataStreamPort(_startPortName);
3529       outDSPort->setProperties(_properties);
3530
3531       node   = proc->getChildByName(_endNodeName);
3532       inDSPort = node->getInputDataStreamPort(_endPortName);
3533       _oldProp = inDSPort->getProperties();
3534       inDSPort->setProperties(_properties);
3535
3536       std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3537       SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3538       subject->update(SETVALUE, 0, subject);
3539       return true;
3540     }
3541   catch (Exception& ex)
3542     {
3543       DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3544       setErrorMsg(ex);
3545       return false;
3546     }
3547 }
3548
3549 bool CommandSetLinkProperties::localReverse()
3550 {
3551   DEBTRACE("CommandSetLinkProperties::localReverse");
3552   try
3553     {
3554       Proc* proc = GuiContext::getCurrent()->getProc();
3555       Node* node;
3556       InputDataStreamPort* inDSPort = 0;
3557       OutputDataStreamPort* outDSPort = 0;
3558
3559       node   = proc->getChildByName(_startNodeName);
3560       outDSPort = node->getOutputDataStreamPort(_startPortName);
3561       outDSPort->setProperties(_properties);
3562
3563       node   = proc->getChildByName(_endNodeName);
3564       inDSPort = node->getInputDataStreamPort(_endPortName);
3565       inDSPort->setProperties(_oldProp);
3566
3567       std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3568       SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3569       subject->update(SETVALUE, 0, subject);
3570       return true;
3571     }
3572   catch (Exception& ex)
3573     {
3574       DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3575       setErrorMsg(ex);
3576       return false;
3577     }
3578 }
3579
3580 // ----------------------------------------------------------------------------
3581
3582 CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName(std::string node, std::string funcName)
3583   : Command(), _nodeName(node), _funcName(funcName)
3584 {
3585   DEBTRACE("CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName " << node << " " <<funcName);
3586   _oldName.clear();
3587 }
3588
3589 std::string CommandSetFuncNodeFunctionName::dump()
3590 {
3591   string ret ="CommandSetFuncNodeFunctionName " + _nodeName + " " + _funcName;
3592   return ret;
3593 }
3594
3595 bool CommandSetFuncNodeFunctionName::localExecute()
3596 {
3597   DEBTRACE("CommandSetFuncNodeFunctionName::localExecute");
3598   try
3599     {
3600       Proc* proc = GuiContext::getCurrent()->getProc();
3601       Node* node = proc->getChildByName(_nodeName);
3602       if (_funcName.empty())
3603         {
3604           GuiContext::getCurrent()->_lastErrorMessage = "InlineFuncNode function name empty: " + _nodeName;
3605           return false;
3606         }
3607       if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3608         {
3609           _oldName = funcNode->getFname();
3610           funcNode->setFname(_funcName);
3611           return true;
3612         }
3613       else
3614         {
3615           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3616           return false;
3617         }
3618     }
3619   catch (Exception& ex)
3620     {
3621       DEBTRACE("CommandSetFuncNodeFunctionName::localExecute() : " << ex.what());
3622       setErrorMsg(ex);
3623       return false;
3624     }  
3625 }
3626
3627 bool CommandSetFuncNodeFunctionName::localReverse()
3628 {
3629   DEBTRACE("CommandSetFuncNodeFunctionName::localReverse");
3630   try
3631     {
3632       Proc* proc = GuiContext::getCurrent()->getProc();
3633       Node* node = proc->getChildByName(_nodeName);
3634       if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3635         {
3636           funcNode->setFname(_oldName);
3637           return true;
3638         }
3639       else
3640         {
3641           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3642           return false;
3643         }
3644     }
3645   catch (Exception& ex)
3646     {
3647       DEBTRACE("CommandSetFuncNodeFunctionName::localReverse() : " << ex.what());
3648       setErrorMsg(ex);
3649       return false;
3650     }  
3651 }
3652
3653 // ----------------------------------------------------------------------------
3654
3655 CommandSetInlineNodeScript::CommandSetInlineNodeScript(std::string node, std::string script)
3656   : Command(), _nodeName(node), _script(script)
3657 {
3658   DEBTRACE("CommandSetInlineNodeScript::CommandSetInlineNodeScript " << node << " " <<script);
3659   _oldScript.clear();
3660 }
3661
3662 std::string CommandSetInlineNodeScript::dump()
3663 {
3664   string ret ="CommandSetInlineNodeScript " + _nodeName;
3665   return ret;
3666 }
3667
3668 bool CommandSetInlineNodeScript::localExecute()
3669 {
3670   DEBTRACE("CommandSetInlineNodeScript::localExecute");
3671   try
3672     {
3673       Proc* proc = GuiContext::getCurrent()->getProc();
3674       Node* node = proc->getChildByName(_nodeName);
3675       if (_script.empty())
3676         {
3677           GuiContext::getCurrent()->_lastErrorMessage = "InlineNode script empty: " + _nodeName;
3678           return false;
3679         }
3680       if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3681         {
3682           _oldScript = inlineNode->getScript();
3683           inlineNode->setScript(_script);
3684           YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3685           SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3686           snode->update(SYNCHRO,0,snode);
3687           return true;
3688         }
3689       else
3690         {
3691           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3692           return false;
3693         }
3694     }
3695   catch (Exception& ex)
3696     {
3697       DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3698       setErrorMsg(ex);
3699       return false;
3700     }  
3701 }
3702
3703 bool CommandSetInlineNodeScript::localReverse()
3704 {
3705   DEBTRACE("CommandSetInlineNodeScript::localReverse");
3706   try
3707     {
3708       Proc* proc = GuiContext::getCurrent()->getProc();
3709       Node* node = proc->getChildByName(_nodeName);
3710       if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3711         {
3712           inlineNode->setScript(_oldScript);
3713           YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3714           SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3715           snode->update(SYNCHRO,0,snode);
3716           return true;
3717         }
3718       else
3719         {
3720           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3721           return false;
3722         }
3723     }
3724   catch (Exception& ex)
3725     {
3726       DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3727       setErrorMsg(ex);
3728       return false;
3729     }  
3730 }
3731
3732 // ----------------------------------------------------------------------------
3733
3734 CommandAddComponentInstance::CommandAddComponentInstance(std::string compoName,
3735                                                          std::string container,
3736                                                          std::string name)
3737   : Command(), _compoName(compoName), _container(container), _name(name), _subcompo(0)
3738 {
3739   DEBTRACE("CommandAddComponentInstance::CommandAddComponentInstance " <<_compoName);
3740 }
3741
3742 std::string CommandAddComponentInstance::dump()
3743 {
3744   string ret ="CommandAddComponentInstance " + _compoName + " " + _container + " " + _name;
3745   return ret;
3746 }
3747
3748 bool CommandAddComponentInstance::localExecute()
3749 {
3750   DEBTRACE("CommandAddComponentInstance::localExecute "<< _compoName << " " << _container << " " << _name);
3751   try
3752     {
3753       Proc* proc = GuiContext::getCurrent()->getProc();
3754       YASSERT(proc->containerMap.count(_container));
3755       Container *cont = proc->containerMap[_container];
3756       ComponentInstance* compoInst = new SalomeComponent(_compoName);
3757       compoInst->setContainer(cont);
3758       proc->addComponentInstance(compoInst, _name);
3759       
3760       SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
3761       _subcompo = sproc->addSubjectComponent(compoInst);
3762       _name = compoInst->getInstanceName();
3763       DEBTRACE(_name);
3764       return true;
3765     }
3766   catch (Exception& ex)
3767     {
3768       DEBTRACE("CommandAddComponentInstance::localExecute() : " << ex.what());
3769       setErrorMsg(ex);
3770       return false;
3771     }
3772 }
3773
3774 bool CommandAddComponentInstance::localReverse()
3775 {
3776   DEBTRACE("CommandAddComponentInstance::localReverse");
3777   try
3778     {
3779       Proc* proc = GuiContext::getCurrent()->getProc();
3780       YASSERT(proc->componentInstanceMap.count(_name));
3781       ComponentInstance *compo = proc->componentInstanceMap[_name];
3782       YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
3783       _subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
3784       YASSERT(!_subcompo->hasServices());
3785       Container *cont = compo->getContainer();
3786       YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
3787       SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3788       subcont->detachComponent(_subcompo);
3789       GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
3790       proc->removeComponentInstance(compo);
3791       return true;
3792     }
3793   catch (Exception& ex)
3794     {
3795       DEBTRACE("CommandAddComponentInstance::localReverse() : " << ex.what());
3796       setErrorMsg(ex);
3797       return false;
3798     }
3799 }
3800
3801 // ----------------------------------------------------------------------------
3802 CommandSetExecutionMode::CommandSetExecutionMode(std::string nodeName, std::string mode)
3803   : Command(), _mode(mode),_nodeName(nodeName)
3804 {
3805   DEBTRACE("CommandSetExecutionMode::CommandSetExecutionMode " << nodeName << " " << mode);
3806   _oldmode = "local";
3807 }
3808
3809 std::string CommandSetExecutionMode::dump()
3810 {
3811   string ret ="CommandSetExecutionMode " + _mode + " " + _nodeName;
3812   return ret;
3813 }
3814
3815 bool CommandSetExecutionMode::localExecute()
3816 {
3817   DEBTRACE("CommandSetExecutionMode::localExecute");
3818   try
3819     {
3820       Proc* proc = GuiContext::getCurrent()->getProc();
3821       Node* node = proc->getChildByName(_nodeName);
3822       if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3823         {
3824           _oldmode = pyNode->getExecutionMode();
3825           pyNode->setExecutionMode(_mode);
3826           SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3827           snode->update(UPDATE, 0, 0);
3828           return true;
3829         }
3830       else
3831         {
3832           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3833           return false;
3834         }
3835     }
3836   catch (Exception& ex)
3837     {
3838       DEBTRACE("CommandSetExecutionMode::localExecute() : " << ex.what());
3839       setErrorMsg(ex);
3840       return false;
3841     }
3842 }
3843
3844 bool CommandSetExecutionMode::localReverse()
3845 {
3846   DEBTRACE("CommandSetExecutionMode::localReverse");
3847   try
3848     {
3849       if (_oldmode == _mode) return true;
3850       Proc* proc = GuiContext::getCurrent()->getProc();
3851       Node* node = proc->getChildByName(_nodeName);
3852       if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3853         {
3854           pyNode->setExecutionMode(_oldmode);
3855           SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3856           snode->update(UPDATE, 0, 0);
3857           return true;
3858         }
3859       else
3860         {
3861           GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3862           return false;
3863         }
3864     }
3865   catch (Exception& ex)
3866     {
3867       DEBTRACE("CommandSetExecutionMode::localReverse() : " << ex.what());
3868       setErrorMsg(ex);
3869       return false;
3870     }
3871   return true;
3872 }
3873
3874
3875 // ----------------------------------------------------------------------------
3876
3877 CommandSetContainer::CommandSetContainer(std::string nodeName, std::string container)
3878   : Command(), _container(container),_nodeName(nodeName)
3879 {
3880   DEBTRACE("CommandSetContainer::CommandSetContainer " << nodeName << " " << container);
3881   _oldcont = "DefaultContainer";
3882 }
3883
3884 std::string CommandSetContainer::dump()
3885 {
3886   string ret ="CommandSetContainer " + _container + " " + _nodeName;
3887   return ret;
3888 }
3889
3890 bool CommandSetContainer::localExecute()
3891 {
3892   DEBTRACE("CommandSetContainer::localExecute");
3893   try
3894     {
3895       Proc* proc = GuiContext::getCurrent()->getProc();
3896       if (proc->containerMap.count(_container))
3897         {
3898           Container *cont = proc->containerMap[_container];
3899           Node* node = proc->getChildByName(_nodeName);
3900           if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3901             {
3902               Container* oldcont = pyNode->getContainer();
3903               if(oldcont)
3904                 _oldcont = pyNode->getContainer()->getName();
3905               pyNode->setContainer(cont);
3906               SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3907               SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3908               snode->update(ASSOCIATE, 0, subcont);
3909               return true;
3910             }
3911           else
3912             {
3913               GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3914               return false;
3915             }
3916         }
3917       else
3918         GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
3919       return false;
3920     }
3921   catch (Exception& ex)
3922     {
3923       DEBTRACE("CommandSetContainer::localExecute() : " << ex.what());
3924       setErrorMsg(ex);
3925       return false;
3926     }
3927 }
3928
3929 bool CommandSetContainer::localReverse()
3930 {
3931   DEBTRACE("CommandSetContainer::localReverse");
3932   try
3933     {
3934       if (_oldcont == _container) return true;
3935       Proc* proc = GuiContext::getCurrent()->getProc();
3936       if (proc->containerMap.count(_oldcont))
3937         {
3938           Container *cont = proc->containerMap[_oldcont];
3939           Node* node = proc->getChildByName(_nodeName);
3940           if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3941             {
3942               pyNode->setContainer(cont);
3943               SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3944               SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3945               snode->update(ASSOCIATE, 0, subcont);
3946               return true;
3947             }
3948           else
3949             {
3950               GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3951               return false;
3952             }
3953         }
3954       else
3955         GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
3956       return false;
3957     }
3958   catch (Exception& ex)
3959     {
3960       DEBTRACE("CommandSetContainer::localReverse() : " << ex.what());
3961       setErrorMsg(ex);
3962       return false;
3963     }
3964   return true;
3965 }
3966
3967
3968   
3969 // ----------------------------------------------------------------------------
3970
3971 CommandAssociateComponentToContainer::CommandAssociateComponentToContainer(std::string instanceName,
3972                                                                            std::string container)
3973   : Command(), _container(container),_instanceName(instanceName)
3974 {
3975   DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer " << instanceName << " " << container);
3976   _oldcont = "DefaultContainer";
3977 }
3978
3979 std::string CommandAssociateComponentToContainer::dump()
3980 {
3981   string ret ="CommandAssociateComponentToContainer " + _container + " " + _instanceName;
3982   return ret;
3983 }
3984
3985 bool CommandAssociateComponentToContainer::localExecute()
3986 {
3987   DEBTRACE("CommandAssociateComponentToContainer::localExecute");
3988   try
3989     {
3990       Proc* proc = GuiContext::getCurrent()->getProc();
3991       if (proc->containerMap.count(_container))
3992         {
3993           Container *cont = proc->containerMap[_container];
3994           if (proc->componentInstanceMap.count(_instanceName))
3995             {
3996               DEBTRACE(_instanceName);
3997               ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
3998               if (compo->getContainer())
3999                 _oldcont = compo->getContainer()->getName();
4000               compo->setContainer(cont);
4001
4002               YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4003               SubjectComponent *scomp =  GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4004               YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4005               SubjectContainerBase *subcont =  GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4006               scomp->addSubjectReference(subcont);
4007               if (scomp->_subRefContainer)
4008                 subcont->moveComponent(scomp->_subRefContainer);
4009               else
4010                 scomp->_subRefContainer = subcont->attachComponent(scomp);
4011               scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4012               return true;
4013             }
4014           else
4015             GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4016         }
4017       else
4018         GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
4019       return false;
4020     }
4021   catch (Exception& ex)
4022     {
4023       DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
4024       setErrorMsg(ex);
4025       return false;
4026     }
4027 }
4028
4029 bool CommandAssociateComponentToContainer::localReverse()
4030 {
4031   DEBTRACE("CommandAssociateComponentToContainer::localReverse");
4032   try
4033     {
4034       if (_oldcont == _container) return true;
4035       Proc* proc = GuiContext::getCurrent()->getProc();
4036       if (proc->containerMap.count(_oldcont))
4037         {
4038           Container *cont = proc->containerMap[_oldcont];
4039           if (proc->componentInstanceMap.count(_instanceName))
4040             {
4041               DEBTRACE(_instanceName);
4042               ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4043               compo->setContainer(cont);
4044
4045               YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4046               SubjectComponent *scomp =  GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4047               YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4048               SubjectContainerBase *subcont =  GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4049               scomp->addSubjectReference(subcont);
4050               if (scomp->_subRefContainer)
4051                 subcont->moveComponent(scomp->_subRefContainer);
4052               else
4053                 scomp->_subRefContainer = subcont->attachComponent(scomp);
4054               scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4055               return true;
4056             }
4057           else
4058             GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4059         }
4060       else
4061         GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
4062       return false;
4063     }
4064   catch (Exception& ex)
4065     {
4066       DEBTRACE("CommandAssociateComponentToContainer::localReverse() : " << ex.what());
4067       setErrorMsg(ex);
4068       return false;
4069     }
4070   return true;
4071 }
4072
4073 // ----------------------------------------------------------------------------
4074
4075 CommandAssociateServiceToComponent::CommandAssociateServiceToComponent(std::string service,
4076                                                                        std::string instanceName)
4077   : Command(), _service(service), _instanceName(instanceName)
4078 {
4079   DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4080   _oldInstance="";
4081 }
4082
4083 std::string CommandAssociateServiceToComponent::dump()
4084 {
4085   string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4086   return ret;
4087 }
4088
4089 bool CommandAssociateServiceToComponent::localExecute()
4090 {
4091   DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4092   try
4093     {
4094       Proc* proc = GuiContext::getCurrent()->getProc();
4095       if (_service == proc->getName()) return false; // proc is not an elementary node
4096       Node* node = proc->getChildByName(_service);
4097       if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4098         {
4099           if (proc->componentInstanceMap.count(_instanceName))
4100             {
4101               DEBTRACE(_instanceName);
4102               ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4103               service->setComponent(compo);
4104
4105               YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4106               SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4107               SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4108               YASSERT(ssnode);
4109               YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4110               SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4111               snode->addSubjectReference(subCompo);
4112               if (ssnode->_subRefComponent)
4113                 {
4114                   SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4115                   YASSERT(oldcomp);
4116                   _oldInstance = oldcomp->getName();
4117                   _oldcont = oldcomp->getComponent()->getContainer()->getName();
4118                   subCompo->moveService(ssnode->_subRefComponent);
4119                 }
4120               else
4121                 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4122
4123               return true;
4124             }
4125           else
4126             GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4127         }
4128       else
4129         GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4130       return false;
4131     }
4132   catch (Exception& ex)
4133     {
4134       DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4135       setErrorMsg(ex);
4136       return false;
4137     }
4138 }
4139
4140 bool CommandAssociateServiceToComponent::localReverse()
4141 {
4142   DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4143   try
4144     {
4145       Proc* proc = GuiContext::getCurrent()->getProc();
4146       if (_service == proc->getName()) return false; // proc is not an elementary node
4147       Node* node = proc->getChildByName(_service);
4148       if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4149         {
4150           ComponentInstance *compo;
4151           if (!proc->componentInstanceMap.count(_oldInstance))
4152             {
4153               //component instance does not exist anymore recreate it
4154               ComponentInstance *oldcompo = service->getComponent();
4155               compo = oldcompo->cloneAlways();
4156               compo->setName(_oldInstance);
4157               proc->addComponentInstance(compo, _oldInstance);
4158               Container *cont = proc->containerMap[_oldcont];
4159               compo->setContainer(cont);
4160               SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
4161               sproc->addSubjectComponent(compo);
4162             }
4163           else
4164             {
4165               compo = proc->componentInstanceMap[_oldInstance];
4166             }
4167
4168           DEBTRACE(_oldInstance);
4169           service->setComponent(compo);
4170
4171           YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4172           SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4173           SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4174           YASSERT(ssnode);
4175           YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4176           SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4177           snode->addSubjectReference(subCompo);
4178           if (ssnode->_subRefComponent)
4179             subCompo->moveService(ssnode->_subRefComponent);
4180           else
4181             ssnode->_subRefComponent = subCompo->attachService(ssnode);
4182
4183           return true;
4184         }
4185       else
4186         GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4187       return false;
4188     }
4189   catch (Exception& ex)
4190     {
4191       DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4192       setErrorMsg(ex);
4193       return false;
4194     }
4195 }
4196
4197 // ----------------------------------------------------------------------------
4198
4199 CommandAddComponentFromCatalog::CommandAddComponentFromCatalog(YACS::ENGINE::Catalog* catalog,
4200                                                                std::string position,
4201                                                                std::string compo,
4202                                                                std::string service)
4203   : Command(), _catalog(catalog), _position(position), _compo(compo), _service(service)
4204 {
4205   DEBTRACE("CommandAddComponentFromCatalog::CommandAddComponentFromCatalog " << position << " " << compo << " " << service);
4206   _nameInProc="";
4207   _createdInstance = false;
4208 }
4209
4210 std::string CommandAddComponentFromCatalog::dump()
4211 {
4212   string ret = "CommandAddComponentFromCatalog " + _position + " " + _compo + " " + _service;
4213   return ret;
4214 }
4215     
4216 bool CommandAddComponentFromCatalog::localExecute()
4217 {
4218   DEBTRACE("CommandAddComponentFromCatalog::localExecute");
4219   try
4220     {
4221       DEBTRACE("_nameInProc: " << _nameInProc);
4222       Proc* proc = GuiContext::getCurrent()->getProc();
4223       Node* node = proc;
4224       if (!_position.empty()) node = proc->getChildByName(_position);
4225       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4226       SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4227       SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4228       YASSERT(ssnode);
4229       if (_catalog->_componentMap.count(_compo))
4230         {
4231           YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compo];
4232           if (compodef->_serviceMap.count(_service))
4233             {
4234               Proc* proc = GuiContext::getCurrent()->getProc();
4235               ComponentInstance *instance =ssnode->_serviceNode->getComponent();
4236               YASSERT(instance);
4237               SubjectComponent* subCompo = 0;
4238               _createdInstance = false;
4239               if(!GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
4240                 {
4241                   _createdInstance = true;
4242                   //automatic rename of the component instance by the proc on first execute
4243                   DEBTRACE("name given to proc:" << _nameInProc);
4244                   proc->addComponentInstance(instance,_nameInProc, true);
4245                   _nameInProc= instance->getInstanceName();
4246                   DEBTRACE("name given by proc:" << _nameInProc);
4247                   subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
4248                 }
4249               else 
4250                 subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
4251               YASSERT(subCompo);
4252               ssnode->addSubjectReference(subCompo);
4253               YASSERT(! ssnode->_subRefComponent);
4254               ssnode->_subRefComponent = subCompo->attachService(ssnode);
4255             }
4256         }
4257       return true;
4258     }
4259   catch (Exception& ex)
4260     {
4261       DEBTRACE("CommandAddComponentFromCatalog::localExecute() : " << ex.what());
4262       setErrorMsg(ex);
4263       return false;
4264     }      
4265 }
4266
4267 bool CommandAddComponentFromCatalog::localReverse()
4268 {
4269   DEBTRACE("CommandAddComponentFromCatalog::localReverse");
4270   try
4271     {
4272       Proc* proc = GuiContext::getCurrent()->getProc();
4273       Node* node = proc;
4274       if (!_position.empty()) node = proc->getChildByName(_position);
4275       YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4276       SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4277       SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4278       YASSERT(ssnode);
4279
4280       DEBTRACE("_nameInProc: " << _nameInProc);
4281       YASSERT(proc->componentInstanceMap.count(_nameInProc));
4282       ComponentInstance *compo = proc->componentInstanceMap[_nameInProc];
4283       YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4284       SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4285
4286       subCompo->detachService(ssnode);
4287       if (subCompo->hasServices())
4288         throw YACS::Exception("Component instance with services attached, not removed");
4289       Container *cont = compo->getContainer();
4290       YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4291       SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4292       subcont->detachComponent(subCompo);
4293       //remove componentInstance from proc, from context
4294       if (_createdInstance)
4295         {
4296           GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
4297           proc->removeComponentInstance(compo);
4298         }
4299       DEBTRACE("_nameInProc: " << _nameInProc);
4300       return true;
4301     }
4302   catch (Exception& ex)
4303     {
4304       DEBTRACE("CommandAddComponentFromCatalog::localReverse() : " << ex.what());
4305       setErrorMsg(ex);
4306       return false;
4307     }      
4308 }
4309