1 // Copyright (C) 2006-2024 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "commandsProc.hxx"
24 #include "ComposedNode.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"
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"
58 #include "guiContext.hxx"
65 #include "YacsTrace.hxx"
70 using namespace YACS::ENGINE;
71 using namespace YACS::HMI;
74 static std::map<int, std::string> createErrorMsgMap()
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";
81 std::map<int, std::string> ErrorMsg = createErrorMsgMap();
83 void setErrorMsg(YACS::Exception& ex)
85 DEBTRACE("errorNumber= "<<ex.errNumber);
86 if(ex.errNumber > 0 && ErrorMsg.count(ex.errNumber) != 0)
88 DEBTRACE(ErrorMsg[ex.errNumber]);
89 GuiContext::getCurrent()->_lastErrorMessage = ex.what() + ErrorMsg[ex.errNumber];
92 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
95 std::map<int, std::string> ProcInvoc::_typeNameMap;
97 // ----------------------------------------------------------------------------
99 ProcInvoc::ProcInvoc()
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";
136 TypeOfElem ProcInvoc::getTypeOfNode(YACS::ENGINE::Node* node)
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;
160 TypeOfElem ProcInvoc::getTypeOfPort(YACS::ENGINE::DataPort* port)
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;
170 std::string ProcInvoc::getTypeName(TypeOfElem type)
172 if (_typeNameMap.count(type))
173 return _typeNameMap[type];
178 // ----------------------------------------------------------------------------
180 CommandAddNodeFromCatalog::CommandAddNodeFromCatalog(YACS::ENGINE::Catalog *catalog,
183 std::string position,
187 : Command(), _catalog(catalog), _compoName(compo), _typeName(type),
188 _position(position), _name(name), _newCompoInst(newCompoInst), _swCase(swCase)
190 DEBTRACE("CommandAddNodeFromCatalog " << compo << " " << type << " " << position << " " << name);
195 std::string CommandAddNodeFromCatalog::dump()
197 string ret ="CommandAddNodeFromCatalog " + _compoName + " " + _typeName + " " + _position + " " + _name;
201 YACS::ENGINE::Node *CommandAddNodeFromCatalog::getNode()
206 YACS::HMI::SubjectNode *CommandAddNodeFromCatalog::getSubjectNode()
211 bool CommandAddNodeFromCatalog::localExecute()
213 DEBTRACE("CommandAddNodeFromCatalog::localExecute");
216 Node *nodeToClone = 0;
219 if (_compoName.empty())
221 if (_catalog->_nodeMap.count(_typeName))
222 nodeToClone = _catalog->_nodeMap[_typeName];
223 else if (_catalog->_composednodeMap.count(_typeName))
224 nodeToClone = _catalog->_composednodeMap[_typeName];
227 if (_catalog->_componentMap.count(_compoName))
229 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compoName];
230 if (compodef->_serviceMap.count(_typeName))
231 nodeToClone = compodef->_serviceMap[_typeName];
234 _typeNode = ProcInvoc::getTypeOfNode(nodeToClone);
236 GuiContext::getCurrent()->setCurrentCatalog(_catalog);
237 Proc* proc = GuiContext::getCurrent()->getProc();
239 ServiceNode *service = 0;
241 if (!_position.empty()) node = proc->getChildByName(_position);
242 ComposedNode* father =dynamic_cast<ComposedNode*> (node);
243 if (father && nodeToClone)
245 son = nodeToClone->clone(0);
247 service = dynamic_cast<ServiceNode*>(son);
250 // Node creation eventually reusing old component instance
251 ComponentInstance *compo = 0;
253 compo = service->getComponent();
257 std::string compoName=compo->getCompoName();
259 std::string compoInstName=compo->getInstanceName();
260 DEBTRACE(compoInstName);
263 ComponentInstance *lastcompo = GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName];
267 DEBTRACE(lastcompo->getInstanceName());
268 service->setComponent(lastcompo); // use the last component instance of the same type and not a new instance
271 GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
274 GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
279 TypeOfElem fatherType = ProcInvoc::getTypeOfNode(father);
283 (dynamic_cast<YACS::ENGINE::Bloc*>(father))->edAddChild(son);
286 (dynamic_cast<YACS::ENGINE::ForLoop*>(father))->edSetNode(son);
289 (dynamic_cast<YACS::ENGINE::WhileLoop*>(father))->edSetNode(son);
292 (dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
295 (dynamic_cast<YACS::ENGINE::ForEachLoopGen*>(father))->edSetNode(son);
298 (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
306 throw YACS::Exception("node from catalog is not correct: check if catalog is up to date!");
308 SubjectComposedNode *sfather = dynamic_cast<SubjectComposedNode*>(GuiContext::getCurrent()->_mapOfSubjectNode[father]);
309 _snode= sfather->addSubjectNode(_node, "", _catalog, _compoName, _typeName);
310 _snode->loadChildren();
313 catch (Exception& ex)
315 DEBTRACE("CommandAddNode::localExecute() : " << ex.what());
323 bool CommandAddNodeFromCatalog::localReverse()
325 DEBTRACE("CommandAddNodeFromCatalog::localReverse");
328 Proc* proc = GuiContext::getCurrent()->getProc();
330 if (_position.empty())
333 nodeName = _position + "." + _name;
335 _node = proc->getChildByName(nodeName);
337 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_node));
338 _snode = GuiContext::getCurrent()->_mapOfSubjectNode[_node];
340 Subject *father=_snode->getParent();
342 DEBTRACE(father->getName());
343 Subject::erase(_snode);
349 father->select(true);
350 father->update(REMOVE,0,0);
354 catch (Exception& ex)
356 DEBTRACE("CommandAddNodeFromCatalog::localReverse(): " << ex.what());
362 // ----------------------------------------------------------------------------
364 CommandReparentNode::CommandReparentNode(std::string position,
365 std::string newParent)
366 : Command(), _position(position), _newParent(newParent)
368 DEBTRACE("CommandReparentNode::CommandReparentNode " << _position << " " << _newParent);
372 std::string CommandReparentNode::dump()
374 string ret ="CommandReparentNode " + _position + " " + _newParent;
378 bool CommandReparentNode::localExecute()
380 DEBTRACE("CommandReparentNode::localExecute");
381 Proc* proc = GuiContext::getCurrent()->getProc();
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;
391 if (_newParent != proc->getName())
393 newF = proc->getChildByName(_newParent);
394 newFather = dynamic_cast<ComposedNode*>(newF);
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;
412 nodeSameName = newFather->getChildByName(node->getName());
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
426 snode->removeExternalLinks();
427 snode->removeExternalControlLinks();
428 sop->houseKeepingAfterCutPaste(true, snode);
429 oldFather->edRemoveChild(node);
430 newFather->edAddChild(node);
431 snp->houseKeepingAfterCutPaste(false, snode);
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;
442 catch (Exception& ex)
444 DEBTRACE("CommandReparentNode::localExecute() : " << ex.what());
450 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
456 bool CommandReparentNode::localReverse()
458 DEBTRACE("CommandReparentNode::localReverse " << _newpos << " " << _oldParent);
459 Proc* proc = GuiContext::getCurrent()->getProc();
463 node = proc->getChildByName(_newpos);
464 ComposedNode *father = node->getFather();
465 ComposedNode *oldFather = proc;
467 if (_oldParent != proc->getName())
469 oldF = proc->getChildByName(_oldParent);
470 oldFather = dynamic_cast<ComposedNode*>(oldF);
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
479 snode->removeExternalLinks();
480 snode->removeExternalControlLinks();
481 snp->houseKeepingAfterCutPaste(true, snode);
482 father->edRemoveChild(node);
483 oldFather->edAddChild(node);
484 sop->houseKeepingAfterCutPaste(false, snode);
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;
492 catch (Exception& ex)
494 DEBTRACE("CommandReparentNode::localReverse() : " << ex.what());
500 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
506 // ----------------------------------------------------------------------------
507 CommandPutInComposedNode::CommandPutInComposedNode(std::string position,
508 std::string newParent,
510 bool toSaveRestoreLinks)
511 : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
513 DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
517 std::string CommandPutInComposedNode::dump()
519 string save = _toSaveRestoreLinks ? "true" : "false";
520 string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save;
525 bool CommandPutInComposedNode::localExecute()
527 DEBTRACE("CommandPutInComposedNode::localExecute");
528 Proc* proc = GuiContext::getCurrent()->getProc();
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);
549 sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
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)
559 if ( _newParent == (*it)->getName() )
561 //get an existing ComposedNode with name _newParent
562 composednode = (*it);
566 // target node was found
569 scomposednode = GuiContext::getCurrent()->_mapOfSubjectNode[composednode];
571 // creation of target node
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);
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
594 scomposednode->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
595 snode->recursiveUpdate(RENAME, 0, snode);
598 catch (Exception& ex)
600 DEBTRACE("CommandPutInComposedNode::localExecute() : " << ex.what());
606 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
612 bool CommandPutInComposedNode::localReverse()
614 DEBTRACE("CommandPutInComposedNode::localReverse");
615 Proc* proc = GuiContext::getCurrent()->getProc();
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
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);
638 //remove composed node oldFather
639 ComposedNode *oldGrandFather = oldFather->getFather();
640 Subject *subog = GuiContext::getCurrent()->_mapOfSubjectNode[oldGrandFather];
641 SubjectComposedNode* sogp = dynamic_cast<SubjectComposedNode*>(subog);
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);
651 snode->restoreLinks();
653 GuiContext::getCurrent()->getSubjectProc()->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
654 sogp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
655 snode->recursiveUpdate(RENAME, 0, snode);
658 catch (Exception& ex)
660 DEBTRACE("CommandPutInComposedNode::localReverse() : " << ex.what());
666 // ----------------------------------------------------------------------------
668 CommandCopyNode::CommandCopyNode(YACS::ENGINE::Proc *fromproc,
669 std::string position,
670 std::string newParent,
672 : Command(), _fromproc(fromproc), _position(position), _newParent(newParent), _newName(""), _clone(0), _case(swCase)
674 DEBTRACE("CommandCopyNode::CommandCopyNode " << _position << " " << _newParent);
677 std::string CommandCopyNode::dump()
679 string ret ="CommandCopyNode " + _position + " " + _newParent;
683 YACS::ENGINE::Node *CommandCopyNode::getNode()
688 bool CommandCopyNode::localExecute()
690 DEBTRACE("CommandCopyNode::localExecute");
691 Proc* proc = GuiContext::getCurrent()->getProc();
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;
701 if (_newParent != proc->getName())
703 newF = proc->getChildByName(_newParent);
704 newFather = dynamic_cast<ComposedNode*>(newF);
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);
714 throw YACS::Exception("Node cannot be cloned");
716 bool sameName = true;
721 s << node->getName();
722 if (nodeSuffix >= 0) // --- first try <0 means without suffix
727 Node *nodeSameName = newFather->getChildByName(s.str());
736 _clone->setName(s.str());
737 _newName = _clone->getName();
739 if (YACS::ENGINE::Switch* theswitch = dynamic_cast<YACS::ENGINE::Switch*>(newFather))
741 DEBTRACE("father is a switch " << newFather->getName());
743 if(theswitch->edGetNode(_case))
745 //the case is already used. Try another one
746 theCase=theswitch->getMaxCase()+1;
748 theswitch->edSetNode(theCase,_clone);
751 newFather->edAddChild(_clone);
753 _newName = _clone->getQualifiedName();
756 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
757 SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(sub);
758 SubjectNode *son = snp->addSubjectNode(_clone);
762 catch (Exception& ex)
764 DEBTRACE("CommandCopyNode::localExecute() : " << ex.what());
768 return (_clone != 0);
771 bool CommandCopyNode::localReverse()
773 DEBTRACE("CommandCopyNode::localReverse " << _position << " " << _newParent);
776 Proc* proc = GuiContext::getCurrent()->getProc();
777 string nodeName = _newParent + "." + _newName;
778 if (_newParent == proc->getName())
781 _clone = proc->getChildByName(nodeName);
783 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_clone));
784 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[_clone];
785 Subject *father = snode->getParent();
786 Subject::erase(snode);
791 father->select(true);
792 father->update(REMOVE,0,0);
796 catch (Exception& ex)
798 DEBTRACE("CommandCopyNode::localReverse(): " << ex.what());
805 // ----------------------------------------------------------------------------
807 CommandRenameNode::CommandRenameNode(std::string position, std::string name)
808 : Command(), _position(position), _name(name)
810 DEBTRACE("CommandRenameNode::CommandRenameNode " << _position << " " << _name);
815 std::string CommandRenameNode::dump()
817 string ret ="CommandRenameNode " + _position + " " + _name;
821 bool CommandRenameNode::localExecute()
823 DEBTRACE("CommandRenameNode::localExecute");
824 Proc* proc = GuiContext::getCurrent()->getProc();
828 if (_position != proc->getName()) node = proc->getChildByName(_position);
829 _oldName = node->getName();
830 node->setName(_name);
834 _newpos = proc->getChildName(node);
835 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
837 snode->recursiveUpdate(RENAME, 0, snode);
839 catch (Exception& ex)
841 DEBTRACE("CommandRenameNode::localExecute() : " << ex.what());
848 bool CommandRenameNode::localReverse()
850 DEBTRACE("CommandRenameNode::localReverse");
851 Proc* proc = GuiContext::getCurrent()->getProc();
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];
860 snode->recursiveUpdate(RENAME, 0, snode);
862 catch (Exception& ex)
864 DEBTRACE("CommandRenameNode::localReverse() : " << ex.what());
871 // ----------------------------------------------------------------------------
873 CommandRenameContainer::CommandRenameContainer(std::string oldName, std::string newName)
874 : Command(), _oldName(oldName), _newName(newName)
876 DEBTRACE("CommandRenameContainer::CommandRenameContainer " << _oldName << " " << _newName);
879 std::string CommandRenameContainer::dump()
881 string ret ="CommandRenameContainer " +_oldName + " " + _newName;
885 bool CommandRenameContainer::localExecute()
887 DEBTRACE("CommandRenameContainer::localExecute");
888 Proc* proc = GuiContext::getCurrent()->getProc();
889 Container *container = 0;
892 YASSERT(proc->containerMap.count(_oldName));
893 container = proc->containerMap[_oldName];
894 if (proc->containerMap.count(_newName))
896 GuiContext::getCurrent()->_lastErrorMessage = "Container name already existing";
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);
907 catch (Exception& ex)
909 DEBTRACE("CommandRenameContainer::localExecute() : " << ex.what());
913 return (container != 0);
916 bool CommandRenameContainer::localReverse()
918 DEBTRACE("CommandRenameContainer::localReverse");
919 Proc* proc = GuiContext::getCurrent()->getProc();
920 Container *container = 0;
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);
933 catch (Exception& ex)
935 DEBTRACE("CommandRenameContainer::localReverse() : " << ex.what());
939 return (container != 0);
942 // ----------------------------------------------------------------------------
944 CommandRenameInDataPort::CommandRenameInDataPort(std::string position,
946 std::string newName, TypeOfElem portType)
947 : Command(), _position(position), _oldName(oldName), _newName(newName), _portType(portType)
949 DEBTRACE("CommandRenameInDataPort::CommandRenameInDataPort "
950 << _position << " " << _oldName<< " " << _newName);
953 std::string CommandRenameInDataPort::dump()
955 string ret ="CommandRenameInDataPort " + _position + " " + _oldName + " " + _newName;
959 bool CommandRenameInDataPort::localExecute()
961 DEBTRACE("CommandRenameInDataPort::localExecute");
962 Proc* proc = GuiContext::getCurrent()->getProc();
966 if (_position != proc->getName()) node = proc->getChildByName(_position);
971 if(_portType==INPUTPORT)
972 port = node->getInputPort(_newName);
974 port = node->getInputDataStreamPort(_newName);
976 catch (Exception& e) {} // --- raised when no existing port with _newName
978 throw Exception("there is already a port with the new name");
980 if(_portType==INPUTPORT)
981 port = node->getInputPort(_oldName);
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);
989 catch (Exception& ex)
991 DEBTRACE("CommandRenameInDataPort::localExecute() : " << ex.what());
998 bool CommandRenameInDataPort::localReverse()
1000 DEBTRACE("CommandRenameInDataPort::localReverse");
1001 Proc* proc = GuiContext::getCurrent()->getProc();
1005 if (_position != proc->getName()) node = proc->getChildByName(_position);
1010 if(_portType==INPUTPORT)
1011 port = node->getInputPort(_oldName);
1013 port = node->getInputDataStreamPort(_oldName);
1015 catch (Exception& e) {} // --- raised when no existing port with _newName
1017 throw Exception("there is already a port with the old name");
1019 if(_portType==INPUTPORT)
1020 port = node->getInputPort(_newName);
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);
1028 catch (Exception& ex)
1030 DEBTRACE("CommandRenameInDataPort::localReverse() : " << ex.what());
1037 // ----------------------------------------------------------------------------
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)
1044 DEBTRACE("CommandRenameOutDataPort::CommandRenameOutDataPort "
1045 << _position << " " << _oldName<< " " << _newName);
1048 std::string CommandRenameOutDataPort::dump()
1050 string ret ="CommandRenameOutDataPort " + _position + " " + _oldName + " " + _newName;
1054 bool CommandRenameOutDataPort::localExecute()
1056 DEBTRACE("CommandRenameOutDataPort::localExecute");
1057 Proc* proc = GuiContext::getCurrent()->getProc();
1061 if (_position != proc->getName()) node = proc->getChildByName(_position);
1065 if(_portType==OUTPUTPORT)
1066 port = node->getOutputPort(_newName);
1068 port = node->getOutputDataStreamPort(_newName);
1070 catch (Exception& e) {} // --- raised when no existing port with _newName
1072 throw Exception("there is already a port with the new name");
1074 if(_portType==OUTPUTPORT)
1075 port = node->getOutputPort(_oldName);
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);
1083 catch (Exception& ex)
1085 DEBTRACE("CommandRenameOutDataPort::localExecute() : " << ex.what());
1092 bool CommandRenameOutDataPort::localReverse()
1094 DEBTRACE("CommandRenameOutDataPort::localReverse");
1095 Proc* proc = GuiContext::getCurrent()->getProc();
1099 if (_position != proc->getName()) node = proc->getChildByName(_position);
1103 if(_portType==OUTPUTPORT)
1104 port = node->getOutputPort(_oldName);
1106 port = node->getOutputDataStreamPort(_oldName);
1108 catch (Exception& e) {} // --- raised when no existing port with _newName
1110 throw Exception("there is already a port with the old name");
1112 if(_portType==OUTPUTPORT)
1113 port = node->getOutputPort(_newName);
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);
1121 catch (Exception& ex)
1123 DEBTRACE("CommandRenameOutDataPort::localReverse() : " << ex.what());
1130 // ----------------------------------------------------------------------------
1132 CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog(YACS::ENGINE::Catalog* catalog,
1133 std::string typeName)
1134 : Command(), _catalog(catalog), _typeName(typeName)
1136 DEBTRACE("CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog: " << typeName);
1139 std::string CommandAddDataTypeFromCatalog::dump()
1141 string ret ="CommandAddDataTypeFromCatalog " + _typeName;
1145 YACS::ENGINE::TypeCode *CommandAddDataTypeFromCatalog::getTypeCode()
1148 if (GuiContext::getCurrent()->getProc()->typeMap.count(_typeName))
1149 return GuiContext::getCurrent()->getProc()->typeMap[_typeName];
1153 bool CommandAddDataTypeFromCatalog::localExecute()
1155 DEBTRACE("CommandAddDataTypeFromCatalog::localExecute");
1156 Proc* proc = GuiContext::getCurrent()->getProc();
1157 if (proc->typeMap.count(_typeName))
1159 DEBTRACE("typecode already existing in proc: " << _typeName);
1160 GuiContext::getCurrent()->_lastErrorMessage = "typeCode already existing in proc: " + _typeName;
1164 if (_catalog->_typeMap.count(_typeName))
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);
1173 GuiContext::getCurrent()->_lastErrorMessage = "typecode not found in catalog: " + _typeName;
1177 bool CommandAddDataTypeFromCatalog::localReverse()
1179 DEBTRACE("CommandAddDataTypeFromCatalog::localReverse");
1182 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
1183 sproc->removeSubjectDataType(_typeName);
1186 catch (Exception& ex)
1188 DEBTRACE("CommandAddDataTypeFromCatalog::localReverse(): " << ex.what());
1195 // ----------------------------------------------------------------------------
1197 CommandAddInputPortFromCatalog::CommandAddInputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1201 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1207 std::string CommandAddInputPortFromCatalog::dump()
1209 string ret ="CommandAddInputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1213 YACS::ENGINE::InputPort *CommandAddInputPortFromCatalog::getInputPort()
1218 SubjectInputPort* CommandAddInputPortFromCatalog::getSubjectInputPort()
1223 bool CommandAddInputPortFromCatalog::localExecute()
1225 DEBTRACE("CommandAddInputPortFromCatalog::localExecute");
1229 Proc* proc = GuiContext::getCurrent()->getProc();
1230 Node* node = proc->getChildByName(_node);
1231 ElementaryNode* father = dynamic_cast<ElementaryNode*>(node);
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]);
1241 DEBTRACE(_typePort << " not found in catalog " << _catalog);
1242 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
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
1251 catch (Exception& ex)
1253 DEBTRACE("CommandAddInputPortFromCatalog::localExecute() : " << ex.what());
1255 if (son) delete son;
1258 return (_inputPort != 0);
1261 bool CommandAddInputPortFromCatalog::localReverse()
1263 DEBTRACE("CommandAddInputPortFromCatalog::localReverse");
1266 Proc* proc = GuiContext::getCurrent()->getProc();
1267 Node *node = proc->getChildByName(_node);
1268 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1270 _inputPort = enode->getInputPort(_name);
1271 YASSERT(_inputPort);
1272 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_inputPort));
1273 _sip = dynamic_cast<SubjectInputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_inputPort]);
1276 Subject *father=_sip->getParent();
1277 Subject::erase(_sip);
1283 father->select(true);
1284 father->update(REMOVE,0,0);
1288 catch (Exception& ex)
1290 DEBTRACE("CommandAddInputPortFromCatalog::localReverse(): " << ex.what());
1296 // ----------------------------------------------------------------------------
1298 CommandAddOutputPortFromCatalog::CommandAddOutputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1302 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1308 std::string CommandAddOutputPortFromCatalog::dump()
1310 string ret ="CommandAddOutputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1314 YACS::ENGINE::OutputPort *CommandAddOutputPortFromCatalog::getOutputPort()
1319 SubjectOutputPort* CommandAddOutputPortFromCatalog::getSubjectOutputPort()
1324 bool CommandAddOutputPortFromCatalog::localExecute()
1326 DEBTRACE("CommandAddOutputPortFromCatalog::localExecute");
1327 OutputPort *son = 0;
1330 Proc* proc = GuiContext::getCurrent()->getProc();
1331 Node* node = proc->getChildByName(_node);
1332 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
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]);
1342 DEBTRACE(_typePort << " not found in catalog");
1343 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
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
1352 catch (Exception& ex)
1354 DEBTRACE("CommandAddOutputPortFromCatalog::localExecute() : " << ex.what());
1356 if (son) delete son;
1359 return (_outputPort != 0);
1362 bool CommandAddOutputPortFromCatalog::localReverse()
1364 DEBTRACE("CommandAddOutputPortFromCatalog::localReverse");
1367 Proc* proc = GuiContext::getCurrent()->getProc();
1368 Node *node = proc->getChildByName(_node);
1369 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1371 _outputPort = enode->getOutputPort(_name);
1372 YASSERT(_outputPort);
1373 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_outputPort));
1374 _sop = dynamic_cast<SubjectOutputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_outputPort]);
1377 Subject *father=_sop->getParent();
1378 Subject::erase(_sop);
1384 father->select(true);
1385 father->update(REMOVE,0,0);
1389 catch (Exception& ex)
1391 DEBTRACE("CommandAddOutputPortFromCatalog::localReverse(): " << ex.what());
1397 // ----------------------------------------------------------------------------
1399 CommandAddIDSPortFromCatalog::CommandAddIDSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1403 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1409 std::string CommandAddIDSPortFromCatalog::dump()
1411 string ret ="CommandAddIDSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1415 YACS::ENGINE::InputDataStreamPort *CommandAddIDSPortFromCatalog::getIDSPort()
1417 DEBTRACE("CommandAddIDSPortFromCatalog");
1421 SubjectInputDataStreamPort* CommandAddIDSPortFromCatalog::getSubjectIDSPort()
1426 bool CommandAddIDSPortFromCatalog::localExecute()
1428 DEBTRACE("CommandAddIDSPortFromCatalog::localExecute");
1429 InputDataStreamPort *son = 0;
1432 Proc* proc = GuiContext::getCurrent()->getProc();
1433 Node* node = proc->getChildByName(_node);
1434 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1437 if (_catalog->_typeMap.count(_typePort))
1438 son = father->edAddInputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1441 DEBTRACE(_typePort << " not found in catalog");
1442 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1446 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1447 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1448 _sip = snode->addSubjectIDSPort(son, _name);
1450 catch (Exception& ex)
1452 DEBTRACE("CommandAddIDSPortFromCatalog::localExecute() : " << ex.what());
1454 if (son) delete son;
1457 return (_IDSPort != 0);
1460 bool CommandAddIDSPortFromCatalog::localReverse()
1462 DEBTRACE("CommandAddIDSPortFromCatalog::localReverse");
1465 Proc* proc = GuiContext::getCurrent()->getProc();
1466 Node *node = proc->getChildByName(_node);
1467 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1469 _IDSPort = enode->getInputDataStreamPort(_name);
1471 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_IDSPort));
1472 _sip = dynamic_cast<SubjectInputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_IDSPort]);
1475 Subject *father=_sip->getParent();
1476 Subject::erase(_sip);
1482 father->select(true);
1483 father->update(REMOVE,0,0);
1487 catch (Exception& ex)
1489 DEBTRACE("CommandAddIDSPortFromCatalog::localReverse(): " << ex.what());
1495 // ----------------------------------------------------------------------------
1497 CommandAddODSPortFromCatalog::CommandAddODSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1501 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1503 DEBTRACE("CommandAddODSPortFromCatalog");
1508 std::string CommandAddODSPortFromCatalog::dump()
1510 string ret ="CommandAddODSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1514 YACS::ENGINE::OutputDataStreamPort *CommandAddODSPortFromCatalog::getODSPort()
1519 SubjectOutputDataStreamPort* CommandAddODSPortFromCatalog::getSubjectODSPort()
1524 bool CommandAddODSPortFromCatalog::localExecute()
1526 DEBTRACE("CommandAddODSPortFromCatalog::localExecute");
1527 OutputDataStreamPort *son = 0;
1530 Proc* proc = GuiContext::getCurrent()->getProc();
1531 Node* node = proc->getChildByName(_node);
1532 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1535 if (_catalog->_typeMap.count(_typePort))
1536 son = father->edAddOutputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1539 DEBTRACE(_typePort << " not found in catalog");
1540 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1544 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1545 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1546 _sop = snode->addSubjectODSPort(son, _name);
1548 catch (Exception& ex)
1550 DEBTRACE("CommandAddODSPortFromCatalog::localExecute() : " << ex.what());
1552 if (son) delete son;
1555 return (_ODSPort != 0);
1558 bool CommandAddODSPortFromCatalog::localReverse()
1560 DEBTRACE("CommandAddODSPortFromCatalog::localReverse");
1563 Proc* proc = GuiContext::getCurrent()->getProc();
1564 Node *node = proc->getChildByName(_node);
1565 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1567 _ODSPort = enode->getOutputDataStreamPort(_name);
1569 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_ODSPort));
1570 _sop = dynamic_cast<SubjectOutputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_ODSPort]);
1573 Subject *father=_sop->getParent();
1574 Subject::erase(_sop);
1580 father->select(true);
1581 father->update(REMOVE,0,0);
1585 catch (Exception& ex)
1587 DEBTRACE("CommandAddODSPortFromCatalog::localReverse(): " << ex.what());
1593 // ----------------------------------------------------------------------------
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.
1598 CommandOrderInputPorts::CommandOrderInputPorts(std::string node,
1601 : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1603 DEBTRACE("CommandOrderInputPorts");
1606 std::string CommandOrderInputPorts::dump()
1610 string ret ="CommandOrderInputPorts " + _node + " " + _port + " " + s.str();
1614 bool CommandOrderInputPorts::localExecute()
1616 DEBTRACE("CommandOrderInputPorts::localExecute " << _node << " " << _port << " " << _isUp);
1617 ElementaryNode* father = 0;
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());
1627 list<InputPort*> plist = father->getSetOfInputPort();
1628 list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1633 if(pos == plist.begin())
1634 pos=plist.end(); // --- cycle
1636 do { pos--; isUp--; } while (isUp);
1641 if (pos == plist.end())
1642 pos = plist.begin(); // --- cycle
1644 pos++; // --- insert before the 2nd next port
1647 InputPort *portBefore = 0;
1648 if (pos != plist.end())
1649 portBefore = (*pos);
1651 plist.remove(portToMove);
1654 DEBTRACE(portBefore->getName());
1655 pos = find(plist.begin(), plist.end(), portBefore);
1657 for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1659 plist.insert(pos, portToMove);
1663 _rank = plist.size();
1664 plist.push_back(portToMove);
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
1673 catch (Exception& ex)
1675 DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1679 return (father != 0);
1682 bool CommandOrderInputPorts::localReverse()
1684 DEBTRACE("CommandOrderInputPorts::localReverse " << _node << " " << _port << " " << _isUp);
1685 ElementaryNode* father = 0;
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());
1697 list<InputPort*> plist = father->getSetOfInputPort();
1698 list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1702 if(pos == plist.begin())
1703 pos=plist.end(); // --- cycle
1705 do { pos--; isUpRev--; } while (isUpRev);
1710 if (pos == plist.end())
1711 pos = plist.begin(); // --- cycle
1713 do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1716 InputPort *portBefore = 0;
1717 if (pos != plist.end())
1718 portBefore = (*pos);
1720 plist.remove(portToMove);
1723 DEBTRACE(portBefore->getName());
1724 pos = find(plist.begin(), plist.end(), portBefore);
1726 for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1728 plist.insert(pos, portToMove);
1732 _rank = plist.size();
1733 plist.push_back(portToMove);
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
1742 catch (Exception& ex)
1744 DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1748 return (father != 0);
1751 // ----------------------------------------------------------------------------
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.
1756 CommandOrderOutputPorts::CommandOrderOutputPorts(std::string node,
1759 : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1761 DEBTRACE("CommandOrderOutputPorts");
1764 std::string CommandOrderOutputPorts::dump()
1768 string ret ="CommandOrderOutputPorts " + _node + " " + _port + " " + s.str();
1772 bool CommandOrderOutputPorts::localExecute()
1774 DEBTRACE("CommandOrderOutputPorts::localExecute " << _node << " " << _port << " " << _isUp);
1775 ElementaryNode* father = 0;
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());
1785 list<OutputPort*> plist = father->getSetOfOutputPort();
1786 list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1791 if(pos == plist.begin())
1792 pos=plist.end(); // --- cycle
1794 do { pos--; isUp--; } while (isUp);
1799 if (pos == plist.end())
1800 pos = plist.begin(); // --- cycle
1802 pos++; // --- insert before the 2nd next port
1805 OutputPort *portBefore = 0;
1806 if (pos != plist.end())
1807 portBefore = (*pos);
1809 plist.remove(portToMove);
1812 DEBTRACE(portBefore->getName());
1813 pos = find(plist.begin(), plist.end(), portBefore);
1815 for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1817 plist.insert(pos, portToMove);
1821 _rank = plist.size();
1822 plist.push_back(portToMove);
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
1831 catch (Exception& ex)
1833 DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1837 return (father != 0);
1840 bool CommandOrderOutputPorts::localReverse()
1842 DEBTRACE("CommandOrderOutputPorts::localReverse " << _node << " " << _port << " " << _isUp);
1843 ElementaryNode* father = 0;
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());
1855 list<OutputPort*> plist = father->getSetOfOutputPort();
1856 list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1860 if(pos == plist.begin())
1861 pos=plist.end(); // --- cycle
1863 do { pos--; isUpRev--; } while (isUpRev);
1868 if (pos == plist.end())
1869 pos = plist.begin(); // --- cycle
1871 do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1874 OutputPort *portBefore = 0;
1875 if (pos != plist.end())
1876 portBefore = (*pos);
1878 plist.remove(portToMove);
1881 DEBTRACE(portBefore->getName());
1882 pos = find(plist.begin(), plist.end(), portBefore);
1884 for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1886 plist.insert(pos, portToMove);
1890 _rank = plist.size();
1891 plist.push_back(portToMove);
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
1900 catch (Exception& ex)
1902 DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1906 return (father != 0);
1909 // ----------------------------------------------------------------------------
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)
1917 DEBTRACE("CommandDestroy::CommandDestroy");
1918 _normalReverse = false;
1921 std::string CommandDestroy::dump()
1923 string ret ="CommandDestroy " + ProcInvoc::getTypeName(_elemType);
1924 ret += " " + _startnode + " " + _startport;
1925 ret += " " + _endnode + " " + _endport;
1929 bool CommandDestroy::localExecute()
1931 DEBTRACE("CommandDestroy::localExecute");
1934 Proc* proc = GuiContext::getCurrent()->getProc();
1935 Subject *subject = 0;
1936 Subject *father = 0;
1951 case SALOMEPYTHONNODE:
1954 case DFTODSFORLOOPNODE:
1955 case DSTODFFORLOOPNODE:
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();
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();
1977 case INPUTDATASTREAMPORT:
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();
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();
1995 case OUTPUTDATASTREAMPORT:
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();
2006 Node* outn = proc->getChildByName(_startnode);
2007 Node* inn = proc->getChildByName(_endnode);
2012 if(_startportType == OUTPUTPORT)
2013 outp = outn->getOutputPort(_startport);
2015 outp = outn->getOutputDataStreamPort(_startport);
2017 if(_endportType == INPUTPORT)
2018 inp = inn->getInputPort(_endport);
2020 inp = inn->getInputDataStreamPort(_endport);
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();
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();
2040 Container *container = proc->containerMap[_startnode];
2041 subject = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
2048 throw Exception("Command Destroy not implemented for that type");
2052 Subject::erase(subject);
2055 father->select(true);
2056 father->update(REMOVE, 0, 0);
2061 catch (Exception& ex)
2063 DEBTRACE("CommandDestroy::localExecute() : " << ex.what());
2069 bool CommandDestroy::localReverse()
2071 DEBTRACE("CommandDestroy::localReverse");
2072 //! nothing to do here, all is done in subcommands
2076 // ----------------------------------------------------------------------------
2078 CommandSetInPortValue::CommandSetInPortValue(std::string node,
2081 : Command(), _node(node), _port(port), _value(value)
2083 DEBTRACE("CommandSetInPortValue::CommandSetInPortValue " << node << " " << port << " " << value);
2087 std::string CommandSetInPortValue::dump()
2089 string ret ="CommandSetInPortValue " + _node + " " + _port + " " + _value;
2093 bool CommandSetInPortValue::localExecute()
2095 DEBTRACE("CommandSetInPortValue::localExecute");
2097 InputPresetPort *inpp = 0;
2098 InputStudyPort *insp = 0;
2099 DataNode *dnode = 0;
2100 SubjectDataPort *sinp = 0;
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];
2112 catch (Exception& ex)
2114 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2122 _oldValue = insp->getAsString();
2123 DEBTRACE("old value="<< _oldValue);
2124 dnode->setData(insp, _value );
2125 sinp->update(SETVALUE, 0, sinp);
2130 PyGILState_STATE gstate = PyGILState_Ensure();
2133 _oldValue = inp->getAsString();
2134 if (_oldValue == "None") _oldValue = "";
2135 DEBTRACE("old value="<< _oldValue);
2137 if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2138 strval = "\"" + _value + "\"";
2141 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2142 inp->edInit("Python", result);
2145 PyGILState_Release(gstate);
2146 sinp->update(SETVALUE, 0, sinp);
2149 catch (Exception& ex)
2151 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2152 //Py_DECREF(result);
2153 PyGILState_Release(gstate);
2159 bool CommandSetInPortValue::localReverse()
2161 DEBTRACE("CommandSetInPortValue::localReverse");
2163 InputPresetPort *inpp = 0;
2164 InputStudyPort *insp = 0;
2165 DataNode *dnode = 0;
2166 SubjectDataPort *sinp = 0;
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];
2178 catch (Exception& ex)
2180 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2188 _value = insp->getAsString();
2189 DEBTRACE("value="<< _value);
2190 DEBTRACE("old value="<< _oldValue);
2191 dnode->setData(insp, _oldValue );
2192 sinp->update(SETVALUE, 0, sinp);
2196 PyObject *result = Py_None;
2197 PyGILState_STATE gstate = PyGILState_Ensure();
2200 _value = inp->getAsString();
2201 DEBTRACE("value="<< _value);
2202 DEBTRACE("old value="<< _oldValue);
2203 if (!_oldValue.empty())
2206 if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2207 strval = "\"" + _oldValue + "\"";
2210 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2212 inp->edInit("Python", result);
2214 PyGILState_Release(gstate);
2215 sinp->update(SETVALUE, 0, sinp);
2218 catch (Exception& ex)
2220 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2221 //Py_DECREF(result);
2222 PyGILState_Release(gstate);
2228 // ----------------------------------------------------------------------------
2230 CommandSetOutPortValue::CommandSetOutPortValue(std::string node,
2233 : Command(), _node(node), _port(port), _value(value)
2235 DEBTRACE("CommandSetOutPortValue::CommandSetOutPortValue " << node << " " << port << " " << value);
2239 std::string CommandSetOutPortValue::dump()
2241 string ret ="CommandSetOutPortValue " + _node + " " + _port + " " + _value;
2245 bool CommandSetOutPortValue::localExecute()
2247 DEBTRACE("CommandSetOutPortValue::localExecute");
2248 OutputPresetPort *outpp = 0;
2249 OutputStudyPort *outsp = 0;
2250 DataNode *dnode = 0;
2251 SubjectDataPort *soutp = 0;
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];
2263 catch (Exception& ex)
2265 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2270 if (!outpp && !outsp)
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";
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";
2287 _oldValue = outsp->getAsString();
2288 DEBTRACE("old value="<< _oldValue);
2289 dnode->setData(outsp, _value );
2290 soutp->update(SETVALUE, 0, soutp);
2297 _oldValue = outpp->getAsString();
2298 if (_oldValue == "None") _oldValue = "";
2299 DEBTRACE("old value="<< _oldValue);
2301 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2302 strval = "\"" + _value + "\"";
2305 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2307 catch (Exception& ex)
2309 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2315 PyGILState_STATE gstate = PyGILState_Ensure();
2318 DEBTRACE(PyObject_Str(result));
2319 val = convertPyObjectXml(outpp->edGetType(), result);
2321 dnode->setData(outpp, val );
2322 soutp->update(SETVALUE, 0, soutp);
2324 catch (Exception& ex)
2326 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2329 PyGILState_Release(gstate);
2334 PyGILState_Release(gstate);
2338 bool CommandSetOutPortValue::localReverse()
2340 DEBTRACE("CommandSetOutPortValue::localReverse");
2341 OutputPresetPort *outpp = 0;
2342 OutputStudyPort *outsp = 0;
2343 DataNode *dnode = 0;
2344 SubjectDataPort *soutp = 0;
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];
2356 catch (Exception& ex)
2358 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2363 if (!outpp && !outsp)
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";
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";
2380 _value = outsp->getAsString();
2381 DEBTRACE("value="<< _value);
2382 DEBTRACE("old value="<< _oldValue);
2383 dnode->setData(outsp, _oldValue );
2384 soutp->update(SETVALUE, 0, soutp);
2388 PyObject *result = Py_None;
2391 _value = outpp->getAsString();
2392 DEBTRACE("value="<< _value);
2393 DEBTRACE("old value="<< _oldValue);
2394 if (!_oldValue.empty())
2397 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2398 strval = "\"" + _value + "\"";
2401 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2404 catch (Exception& ex)
2406 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2412 PyGILState_STATE gstate = PyGILState_Ensure();
2415 DEBTRACE(PyObject_Str(result));
2416 val = convertPyObjectXml(outpp->edGetType(), result);
2418 dnode->setData(outpp, val );
2419 soutp->update(SETVALUE, 0, soutp);
2421 catch (Exception& ex)
2423 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2426 PyGILState_Release(gstate);
2431 PyGILState_Release(gstate);
2435 // ----------------------------------------------------------------------------
2437 CommandSetSwitchSelect::CommandSetSwitchSelect(std::string aSwitch,
2439 : Command(), _switch(aSwitch), _value(value)
2441 DEBTRACE("CommandSetSwitchSelect::CommandSetSwitchSelect");
2445 std::string CommandSetSwitchSelect::dump()
2447 string ret ="CommandSetSwitchSelect " + _switch + " " + _value;
2451 bool CommandSetSwitchSelect::localExecute()
2453 DEBTRACE("CommandSetSwitchSelect::localExecute");
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);
2467 catch (Exception& ex)
2469 DEBTRACE("CommandSetSwitchSelect::localExecute() : " << ex.what());
2476 bool CommandSetSwitchSelect::localReverse()
2478 DEBTRACE("CommandSetSwitchSelect::localReverse");
2481 Proc* proc = GuiContext::getCurrent()->getProc();
2482 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2483 InputPort *condPort = aSwitch->edGetConditionPort();
2484 int val = atoi(_oldValue.c_str());
2485 condPort->edInit(val);
2486 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2487 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2488 snode->update(SETSELECT, 0, snode);
2490 catch (Exception& ex)
2492 DEBTRACE("CommandSetSwitchSelect::localReverse() : " << ex.what());
2499 // ----------------------------------------------------------------------------
2501 CommandSetSwitchCase::CommandSetSwitchCase(std::string aSwitch,
2504 : Command(), _switch(aSwitch), _node(node), _value(value)
2506 DEBTRACE("CommandSetSwitchCase::CommandSetSwitchCase");
2511 std::string CommandSetSwitchCase::dump()
2513 string ret ="CommandSetSwitchCase " + _switch + " " + _node + " " + _value;
2517 bool CommandSetSwitchCase::localExecute()
2519 DEBTRACE("CommandSetSwitchCase::localExecute");
2522 DEBTRACE("CommandSetSwitchCase::localExecute");
2523 Proc* proc = GuiContext::getCurrent()->getProc();
2524 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2525 Node* node = proc->getChildByName(_node);
2526 int val = atoi(_value.c_str());
2527 if (aSwitch->edGetNode(val))
2529 throw YACS::Exception("Set Switch Case impossible: value already used");
2531 int oldVal = aSwitch->getRankOfNode(node);
2532 aSwitch->edChangeCase(oldVal,val);
2534 _oldNode = proc->getChildName(node);
2535 DEBTRACE("CommandSetSwitchCase::localExecute OK " << val);
2536 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2537 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2538 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2539 ssw->update(SETCASE, val, snode);
2540 snode->recursiveUpdate(RENAME, 0, snode);
2543 catch (Exception& ex)
2545 DEBTRACE("CommandSetSwitchCase::localExecute() : " << ex.what());
2551 bool CommandSetSwitchCase::localReverse()
2553 DEBTRACE("CommandSetSwitchCase::localReverse");
2556 DEBTRACE("CommandSetSwitchCase::localReverse");
2557 Proc* proc = GuiContext::getCurrent()->getProc();
2558 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2559 Node* node = proc->getChildByName(_oldNode);
2560 int val = _oldValue;
2561 if (aSwitch->edGetNode(val))
2563 throw YACS::Exception("Set Switch Case impossible: value already used");
2565 int oldVal = aSwitch->getRankOfNode(node);
2566 aSwitch->edChangeCase(oldVal,val);
2567 DEBTRACE("CommandSetSwitchCase::localReverse OK " << val);
2568 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2569 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2570 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2571 ssw->update(SETCASE, val, snode);
2572 snode->recursiveUpdate(RENAME, 0, snode);
2575 catch (Exception& ex)
2577 DEBTRACE("CommandSetSwitchCase::localReverse() : " << ex.what());
2583 // ----------------------------------------------------------------------------
2585 CommandSetForLoopSteps::CommandSetForLoopSteps(std::string forLoop,
2587 : Command(), _forLoop(forLoop), _value(value)
2589 DEBTRACE("CommandSetForLoopSteps::CommandSetForLoopSteps");
2594 std::string CommandSetForLoopSteps::dump()
2596 string ret ="CommandSetForLoopSteps " + _forLoop + " " + _value;
2600 bool CommandSetForLoopSteps::localExecute()
2602 DEBTRACE("CommandSetForLoopSteps::localExecute");
2605 DEBTRACE("CommandSetForLoopSteps::localExecute");
2606 Proc* proc = GuiContext::getCurrent()->getProc();
2607 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2608 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2609 _oldValue = atoi(forLoop->edGetNbOfTimesInputPort()->getAsString().c_str());
2610 int val = atoi(_value.c_str());
2611 nbSteps->edInit(val);
2612 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2613 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2614 snode->update(SETVALUE, 0, snode);
2617 catch (Exception& ex)
2619 DEBTRACE("CommandSetForLoopSteps::localExecute() : " << ex.what());
2625 bool CommandSetForLoopSteps::localReverse()
2627 DEBTRACE("CommandSetForLoopSteps::localReverse");
2630 DEBTRACE("CommandSetForLoopSteps::localReverse");
2631 Proc* proc = GuiContext::getCurrent()->getProc();
2632 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2633 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2634 nbSteps->edInit(_oldValue);
2635 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2636 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2637 snode->update(SETVALUE, 0, snode);
2640 catch (Exception& ex)
2642 DEBTRACE("CommandSetForLoopSteps::localReverse() : " << ex.what());
2648 // ----------------------------------------------------------------------------
2650 CommandSetWhileCondition::CommandSetWhileCondition(std::string whileLoop,
2652 : Command(), _whileLoop(whileLoop), _value(value)
2654 DEBTRACE("CommandSetWhileCondition::CommandSetWhileCondition");
2658 std::string CommandSetWhileCondition::dump()
2660 string ret ="CommandSetWhileCondition " + _whileLoop + " " + _value;
2664 bool CommandSetWhileCondition::localExecute()
2666 DEBTRACE("CommandSetWhileCondition::localExecute");
2669 Proc* proc = GuiContext::getCurrent()->getProc();
2670 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2671 InputPort *cond = whileLoop->edGetConditionPort();
2672 _oldValue = atoi(whileLoop->edGetConditionPort()->getAsString().c_str());
2673 bool val = atoi(_value.c_str());
2675 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2676 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2677 snode->update(SETVALUE, 0, snode);
2680 catch (Exception& ex)
2682 DEBTRACE("CommandSetWhileCondition::localExecute() : " << ex.what());
2688 bool CommandSetWhileCondition::localReverse()
2690 DEBTRACE("CommandSetWhileCondition::localReverse");
2693 Proc* proc = GuiContext::getCurrent()->getProc();
2694 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2695 InputPort *cond = whileLoop->edGetConditionPort();
2696 cond->edInit(_oldValue);
2697 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2698 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2699 snode->update(SETVALUE, 0, snode);
2702 catch (Exception& ex)
2704 DEBTRACE("CommandSetWhileCondition::localReverse() : " << ex.what());
2710 // ----------------------------------------------------------------------------
2712 CommandSetForEachBranch::CommandSetForEachBranch(std::string forEach,
2714 : Command(), _forEach(forEach), _value(value)
2716 DEBTRACE("CommandSetForEachBranch::CommandSetForEachBranch");
2720 std::string CommandSetForEachBranch::dump()
2722 string ret ="CommandSetForEachBranch " + _forEach + " " + _value;
2726 bool CommandSetForEachBranch::localExecute()
2728 DEBTRACE("CommandSetForEachBranch::localExecute");
2731 Proc* proc = GuiContext::getCurrent()->getProc();
2732 Node* node=proc->getChildByName(_forEach);
2733 InputPort *nbBranches = node->getInputPort("nbBranches");
2734 _oldValue = atoi(nbBranches->getAsString().c_str());
2735 int val = atoi(_value.c_str());
2736 nbBranches->edInit(val);
2737 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2738 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2739 spo->update(SETVALUE, 0, spo);
2740 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2741 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2742 snode->update(SETVALUE, 0, snode);
2745 catch (Exception& ex)
2747 DEBTRACE("CommandSetForEachBranch::localExecute() : " << ex.what());
2753 bool CommandSetForEachBranch::localReverse()
2755 DEBTRACE("CommandSetForEachBranch::localReverse");
2758 Proc* proc = GuiContext::getCurrent()->getProc();
2759 Node* node=proc->getChildByName(_forEach);
2760 InputPort *nbBranches = node->getInputPort("nbBranches");
2761 nbBranches->edInit(_oldValue);
2762 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2763 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2764 spo->update(SETVALUE, 0, spo);
2765 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2766 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2767 snode->update(SETVALUE, 0, snode);
2770 catch (Exception& ex)
2772 DEBTRACE("CommandSetForEachBranch::localReverse() : " << ex.what());
2778 // ----------------------------------------------------------------------------
2780 CommandSetAlgo::CommandSetAlgo(std::string optimizer, std::string alglib, std::string symbol)
2781 : Command(), _optimizer(optimizer), _alglib(alglib), _symbol(symbol)
2783 DEBTRACE("CommandSetAlgo::CommandSetAlgo" << _optimizer << " " << _alglib << " " << _symbol);
2788 std::string CommandSetAlgo::dump()
2790 string ret ="CommandSetAlgo " + _optimizer + " " + _alglib + " " + _symbol;
2794 bool CommandSetAlgo::localExecute()
2796 DEBTRACE("CommandSetAlgo::localExecute");
2799 Proc* proc = GuiContext::getCurrent()->getProc();
2800 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2801 loop->setAlgorithm(_alglib,_symbol);
2802 _oldAlglib = _alglib;
2803 _oldSymbol = _symbol;
2804 InputPort *port = loop->edGetPortForOutPool();
2805 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2806 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2807 spo->update(UPDATE, 0, spo);
2808 OutputPort *oport = loop->edGetSamplePort();
2809 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2810 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2811 spo->update(UPDATE, 0, spo);
2812 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2813 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2814 snode->update(SETVALUE, 0, snode);
2817 catch (Exception& ex)
2819 DEBTRACE("CommandSetAlgo::localExecute() : " << ex.what());
2825 bool CommandSetAlgo::localReverse()
2827 DEBTRACE("CommandSetAlgo::localReverse");
2830 Proc* proc = GuiContext::getCurrent()->getProc();
2831 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2832 loop->setAlgorithm(_oldAlglib,_oldSymbol);
2833 InputPort *port = loop->edGetPortForOutPool();
2834 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2835 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2836 spo->update(UPDATE, 0, spo);
2837 OutputPort *oport = loop->edGetSamplePort();
2838 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2839 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2840 spo->update(UPDATE, 0, spo);
2841 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2842 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2843 snode->update(SETVALUE, 0, snode);
2846 catch (Exception& ex)
2848 DEBTRACE("CommandSetAlgo::localReverse() : " << ex.what());
2855 // ----------------------------------------------------------------------------
2857 CommandAddLink::CommandAddLink(std::string outNode, std::string outPort, TypeOfElem outPortType,
2858 std::string inNode, std::string inPort, TypeOfElem inPortType, bool control)
2859 : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2860 _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2862 DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2863 _controlCreatedWithDF = false;
2866 std::string CommandAddLink::dump()
2869 if (_control) s = "true";
2870 string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2874 bool CommandAddLink::localExecute()
2876 DEBTRACE("CommandAddLink::localExecute");
2877 DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2880 Proc* proc = GuiContext::getCurrent()->getProc();
2881 Node* outn = proc->getChildByName(_outNode);
2882 Node* inn = proc->getChildByName(_inNode);
2886 // --- is a control link already existing ?
2887 bool preexistingControl = false;
2891 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2892 if(outn2==father || inn2==father)
2893 preexistingControl = true;
2896 while(outn2->getFather() != father)
2897 outn2 = outn2->getFather();
2898 while(inn2->getFather() != father)
2899 inn2 = inn2->getFather();
2900 OutGate *ogate = outn2->getOutGate();
2901 InGate *igate = inn2->getInGate();
2902 if (ogate->isAlreadyInSet(igate))
2903 preexistingControl = true;
2907 if(_outPortType == OUTPUTPORT)
2908 outp = outn->getOutputPort(_outPort);
2910 outp = outn->getOutputDataStreamPort(_outPort);
2912 if(_inPortType == INPUTPORT)
2913 inp = inn->getInputPort(_inPort);
2915 inp = inn->getInputDataStreamPort(_inPort);
2917 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2918 DEBTRACE(cla->getName());
2919 if (dynamic_cast<OutputDataStreamPort*>(outp))
2920 cla->edAddLink(outp,inp);
2922 cla->edAddDFLink(outp,inp);
2924 cla->edAddLink(outp,inp);
2926 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2927 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
2928 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2929 DEBTRACE(scla->getName());
2930 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2931 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2932 SubjectDataPort *subOutport = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2933 SubjectDataPort *subInport = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2934 SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2936 // --- if control link, identify the nodes linked and draw the control link if not already existing
2940 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2941 if(outn==father || inn==father) return true;
2942 while(outn->getFather() != father)
2943 outn = outn->getFather();
2944 while(inn->getFather() != father)
2945 inn = inn->getFather();
2946 OutGate *ogate = outn->getOutGate();
2947 InGate *igate = inn->getInGate();
2948 if (ogate->isAlreadyInSet(igate))
2950 if (!preexistingControl)
2951 _controlCreatedWithDF = true;
2952 pair<Node*,Node*> keyLink(outn,inn);
2953 if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2955 SubjectNode *sfno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2956 SubjectNode *sfni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2957 if (!sfno || !sfni) return true;
2958 SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2964 catch (Exception& ex)
2966 DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2972 bool CommandAddLink::localReverse()
2974 DEBTRACE("CommandAddLink::localReverse");
2977 SubjectLink *slink =0;
2978 SubjectControlLink *sclink = 0;
2979 Proc* proc = GuiContext::getCurrent()->getProc();
2980 Node* outn = proc->getChildByName(_outNode);
2981 Node* inn = proc->getChildByName(_inNode);
2984 if(_outPortType == OUTPUTPORT)
2985 outp = outn->getOutputPort(_outPort);
2987 outp = outn->getOutputDataStreamPort(_outPort);
2988 if(_inPortType == INPUTPORT)
2989 inp = inn->getInputPort(_inPort);
2991 inp = inn->getInputDataStreamPort(_inPort);
2992 YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(pair<OutPort*,InPort*>(outp,inp)));
2993 slink = GuiContext::getCurrent()->_mapOfSubjectLink[pair<OutPort*,InPort*>(outp,inp)];
2994 if (_controlCreatedWithDF)
2996 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
2997 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
3000 Subject *father = slink->getParent();
3001 Subject::erase(slink);
3006 father->select(true);
3007 father->update(REMOVE,0,0);
3011 father=sclink->getParent();
3012 Subject::erase(sclink);
3017 father->select(true);
3018 father->update(REMOVE,0,0);
3022 catch (Exception& ex)
3024 DEBTRACE("CommandAddLink::localReverse(): " << ex.what());
3030 // ----------------------------------------------------------------------------
3032 CommandAddControlLink::CommandAddControlLink(std::string outNode, std::string inNode)
3033 : Command(), _outNode(outNode), _inNode(inNode)
3035 DEBTRACE("CommandAddControlLink::CommandAddControlLink "<<outNode<<"-->>"<<inNode);
3038 std::string CommandAddControlLink::dump()
3040 string ret ="CommandAddControlLink " + _outNode + " " + _inNode;
3044 bool CommandAddControlLink::localExecute()
3046 DEBTRACE("CommandAddControlLink::localExecute");
3049 Proc* proc = GuiContext::getCurrent()->getProc();
3051 if (! _outNode.empty())
3052 outn = proc->getChildByName(_outNode);
3054 if (! _inNode.empty())
3055 inn = proc->getChildByName(_inNode);
3056 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn,inn);
3057 DEBTRACE(cla->getName());
3058 bool ret= cla->edAddCFLink(outn,inn);
3060 GuiContext::getCurrent()->_lastErrorMessage = "Link already exists";
3062 cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),
3064 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
3065 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
3066 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
3067 DEBTRACE(scla->getName());
3068 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
3069 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
3070 SubjectControlLink *sclink = scla->addSubjectControlLink(sno,sni);
3073 catch (Exception& ex)
3075 DEBTRACE("CommandAddControlLink::localExecute() : " << ex.what());
3081 bool CommandAddControlLink::localReverse()
3083 DEBTRACE("CommandAddControlLink::localReverse");
3086 SubjectControlLink *sclink = 0;
3087 Proc* proc = GuiContext::getCurrent()->getProc();
3088 Node* outn = proc->getChildByName(_outNode);
3089 Node* inn = proc->getChildByName(_inNode);
3090 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
3091 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
3093 Subject *father=sclink->getParent();
3094 Subject::erase(sclink);
3099 father->select(true);
3100 father->update(REMOVE,0,0);
3104 catch (Exception& ex)
3106 DEBTRACE("CommandAddControlLink::localReverse(): " << ex.what());
3112 // ----------------------------------------------------------------------------
3114 CommandAddContainerBase::CommandAddContainerBase(std::string name, std::string refContainer)
3115 : Command(), _name(name), _containerToClone(refContainer), _subcont(0)
3117 DEBTRACE("CommandAddContainerBase::CommandAddContainerBase " << name << " " << refContainer);
3120 CommandAddContainerBase::~CommandAddContainerBase()
3124 bool CommandAddContainerBase::localExecute()
3126 DEBTRACE("CommandAddContainerBase::localExecute");
3129 Proc* proc = GuiContext::getCurrent()->getProc();
3130 if (proc->containerMap.count(_name))
3132 GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
3135 Container *container(createNewInstance());
3136 if (! _containerToClone.empty())
3138 if (proc->containerMap.count(_containerToClone))
3140 Container *ref = proc->containerMap[_containerToClone];
3142 container->setProperties(ref->getProperties());
3146 GuiContext::getCurrent()->_lastErrorMessage = "There is no reference container to clone properties";
3150 container->setName(_name);
3151 container->setProc(proc);
3152 proc->containerMap[_name] = container;
3154 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3155 _subcont = sproc->addSubjectContainer(container, _name);
3158 catch (Exception& ex)
3160 DEBTRACE("CommandAddContainerBase::localExecute() : " << ex.what());
3166 bool CommandAddContainerBase::localReverse()
3168 DEBTRACE("CommandAddContainerBase::localReverse");
3171 Proc* proc = GuiContext::getCurrent()->getProc();
3172 YASSERT(proc->containerMap.count(_name));
3173 Container *container = proc->containerMap[_name];
3174 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
3175 _subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
3176 YASSERT(!_subcont->isUsed());
3177 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3178 sproc->removeSubjectContainer(_subcont);
3181 catch (Exception& ex)
3183 DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
3189 // ----------------------------------------------------------------------------
3191 CommandAddContainer::CommandAddContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3195 std::string CommandAddContainer::dump()
3197 string ret ="CommandAddContainer " + _name + " " + _containerToClone;
3201 Container *CommandAddContainer::createNewInstance() const
3203 return new SalomeContainer;
3206 // ----------------------------------------------------------------------------
3208 CommandAddHPContainer::CommandAddHPContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3212 std::string CommandAddHPContainer::dump()
3214 string ret ="CommandAddHPContainer " + _name + " " + _containerToClone;
3218 Container *CommandAddHPContainer::createNewInstance() const
3220 return new SalomeHPContainer;
3223 // ----------------------------------------------------------------------------
3225 CommandSetNodeProperties::CommandSetNodeProperties(std::string position, std::map<std::string,std::string> properties)
3226 : Command(), _position(position), _properties(properties)
3228 DEBTRACE("CommandSetNodeProperties::CommandSetNodeProperties " << position);
3232 std::string CommandSetNodeProperties::dump()
3234 string ret ="CommandSetNodeProperties " + _position;
3238 bool CommandSetNodeProperties::localExecute()
3240 DEBTRACE("CommandSetNodeProperties::localExecute");
3243 Proc* proc = GuiContext::getCurrent()->getProc();
3246 if (!_position.empty()) node = proc->getChildByName(_position);
3250 _oldProp = node->getPropertyMap();
3251 node->setProperties(_properties);
3252 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3253 snode->update(SETVALUE, 0, snode);
3256 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3259 catch (Exception& ex)
3261 DEBTRACE("CommandSetNodeProperties::localExecute() : " << ex.what());
3267 bool CommandSetNodeProperties::localReverse()
3269 DEBTRACE("CommandSetNodeProperties::localReverse");
3272 Proc* proc = GuiContext::getCurrent()->getProc();
3275 if (!_position.empty()) node = proc->getChildByName(_position);
3279 node->setProperties(_oldProp);
3280 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3281 snode->update(SETVALUE, 0, snode);
3284 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3287 catch (Exception& ex)
3289 DEBTRACE("CommandSetNodeProperties::localReverse() : " << ex.what());
3295 // ----------------------------------------------------------------------------
3297 CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties(std::string compoinstance,
3298 std::map<std::string,std::string> properties)
3299 : Command(), _compoinstance(compoinstance), _properties(properties)
3301 DEBTRACE("CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties " << compoinstance);
3305 std::string CommandSetComponentInstanceProperties::dump()
3307 string ret ="CommandSetComponentInstanceProperties " + _compoinstance;
3311 bool CommandSetComponentInstanceProperties::localExecute()
3313 DEBTRACE("CommandSetComponentInstanceProperties::localExecute");
3316 Proc* proc = GuiContext::getCurrent()->getProc();
3317 if (proc->componentInstanceMap.count(_compoinstance))
3319 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3321 _oldProp = ref->getProperties();
3322 _oldAnon = ref->isAnonymous();
3323 ref->setProperties(_properties);
3324 ref->setAnonymous(false);
3325 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3326 subcompo->update(SETVALUE, 0, subcompo);
3329 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3332 catch (Exception& ex)
3334 DEBTRACE("CommandSetComponentInstanceProperties::localExecute() : " << ex.what());
3340 bool CommandSetComponentInstanceProperties::localReverse()
3342 DEBTRACE("CommandSetComponentInstanceProperties::localReverse");
3345 Proc* proc = GuiContext::getCurrent()->getProc();
3346 if (proc->componentInstanceMap.count(_compoinstance))
3348 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3350 ref->setProperties(_oldProp);
3351 ref->setAnonymous(_oldAnon);
3352 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3353 subcompo->update(SETVALUE, 0, subcompo);
3356 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3359 catch (Exception& ex)
3361 DEBTRACE("CommandSetComponentInstanceProperties::localReverse() : " << ex.what());
3367 // ----------------------------------------------------------------------------
3369 CommandSetContainerProperties::CommandSetContainerProperties(std::string container,
3370 std::map<std::string,std::string> properties)
3371 : Command(), _container(container), _properties(properties)
3373 DEBTRACE("CommandSetContainerProperties::CommandSetContainerProperties " << container);
3377 std::string CommandSetContainerProperties::dump()
3379 string ret ="CommandSetContainerProperties " + _container;
3383 bool CommandSetContainerProperties::localExecute()
3385 DEBTRACE("CommandSetContainerProperties::localExecute");
3388 Proc* proc = GuiContext::getCurrent()->getProc();
3389 if (proc->containerMap.count(_container))
3391 Container *ref(proc->containerMap[_container]);
3393 _oldProp = ref->getProperties();
3394 ref->setProperties(_properties);
3395 SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[ref]);
3396 scont->update(UPDATE, 0, scont);
3397 scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
3400 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3403 catch (Exception& ex)
3405 DEBTRACE("CommandSetContainerProperties::localExecute() : " << ex.what());
3411 bool CommandSetContainerProperties::localReverse()
3413 DEBTRACE("CommandSetContainerProperties::localReverse");
3416 Proc* proc = GuiContext::getCurrent()->getProc();
3417 if (proc->containerMap.count(_container))
3419 Container *ref = proc->containerMap[_container];
3421 ref->setProperties(_oldProp);
3424 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3427 catch (Exception& ex)
3429 DEBTRACE("CommandSetContainerProperties::localReverse() : " << ex.what());
3435 // ----------------------------------------------------------------------------
3437 CommandSetDSPortProperties::CommandSetDSPortProperties(std::string node, std::string port, bool isInport,
3438 std::map<std::string,std::string> properties)
3439 : Command(), _nodeName(node), _portName(port), _isInport(isInport), _properties(properties)
3441 DEBTRACE("CommandSetDSPortProperties::CommandSetDSPortProperties " << node << "." << port << " " << isInport);
3445 std::string CommandSetDSPortProperties::dump()
3448 if (_isInport) s = "true";
3449 string ret ="CommandSetDSPortProperties " + _nodeName + " " + _portName + " " + s;
3453 bool CommandSetDSPortProperties::localExecute()
3455 DEBTRACE("CommandSetDSPortProperties::localExecute");
3458 Proc* proc = GuiContext::getCurrent()->getProc();
3459 Node* node = proc->getChildByName(_nodeName);
3460 DataStreamPort* DSPort = 0;
3462 DSPort = node->getInputDataStreamPort(_portName);
3464 DSPort = node->getOutputDataStreamPort(_portName);
3465 _oldProp = DSPort->getProperties();
3466 DSPort->setProperties(_properties);
3469 catch (Exception& ex)
3471 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3477 bool CommandSetDSPortProperties::localReverse()
3479 DEBTRACE("CommandSetDSPortProperties::localReverse");
3482 Proc* proc = GuiContext::getCurrent()->getProc();
3483 Node* node = proc->getChildByName(_nodeName);
3484 DataStreamPort* DSPort = 0;
3486 DSPort = node->getInputDataStreamPort(_portName);
3488 DSPort = node->getOutputDataStreamPort(_portName);
3489 DSPort->setProperties(_oldProp);
3492 catch (Exception& ex)
3494 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3500 // ----------------------------------------------------------------------------
3502 CommandSetLinkProperties::CommandSetLinkProperties(std::string startnode, std::string startport,
3503 std::string endnode, std::string endport,
3504 std::map<std::string,std::string> properties)
3505 : Command(), _startNodeName(startnode), _startPortName(startport),
3506 _endNodeName(endnode), _endPortName(endport),
3507 _properties(properties)
3509 DEBTRACE("CommandSetLinkProperties::CommandSetLinkProperties " );
3513 std::string CommandSetLinkProperties::dump()
3515 string ret ="CommandSetLinkProperties " + _startNodeName + " " + _startPortName + " " + _endNodeName + " " + _endPortName;
3519 bool CommandSetLinkProperties::localExecute()
3521 DEBTRACE("CommandSetLinkProperties::localExecute");
3524 Proc* proc = GuiContext::getCurrent()->getProc();
3526 InputDataStreamPort* inDSPort = 0;
3527 OutputDataStreamPort* outDSPort = 0;
3529 node = proc->getChildByName(_startNodeName);
3530 outDSPort = node->getOutputDataStreamPort(_startPortName);
3531 outDSPort->setProperties(_properties);
3533 node = proc->getChildByName(_endNodeName);
3534 inDSPort = node->getInputDataStreamPort(_endPortName);
3535 _oldProp = inDSPort->getProperties();
3536 inDSPort->setProperties(_properties);
3538 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3539 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3540 subject->update(SETVALUE, 0, subject);
3543 catch (Exception& ex)
3545 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3551 bool CommandSetLinkProperties::localReverse()
3553 DEBTRACE("CommandSetLinkProperties::localReverse");
3556 Proc* proc = GuiContext::getCurrent()->getProc();
3558 InputDataStreamPort* inDSPort = 0;
3559 OutputDataStreamPort* outDSPort = 0;
3561 node = proc->getChildByName(_startNodeName);
3562 outDSPort = node->getOutputDataStreamPort(_startPortName);
3563 outDSPort->setProperties(_properties);
3565 node = proc->getChildByName(_endNodeName);
3566 inDSPort = node->getInputDataStreamPort(_endPortName);
3567 inDSPort->setProperties(_oldProp);
3569 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3570 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3571 subject->update(SETVALUE, 0, subject);
3574 catch (Exception& ex)
3576 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3582 // ----------------------------------------------------------------------------
3584 CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName(std::string node, std::string funcName)
3585 : Command(), _nodeName(node), _funcName(funcName)
3587 DEBTRACE("CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName " << node << " " <<funcName);
3591 std::string CommandSetFuncNodeFunctionName::dump()
3593 string ret ="CommandSetFuncNodeFunctionName " + _nodeName + " " + _funcName;
3597 bool CommandSetFuncNodeFunctionName::localExecute()
3599 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute");
3602 Proc* proc = GuiContext::getCurrent()->getProc();
3603 Node* node = proc->getChildByName(_nodeName);
3604 if (_funcName.empty())
3606 GuiContext::getCurrent()->_lastErrorMessage = "InlineFuncNode function name empty: " + _nodeName;
3609 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3611 _oldName = funcNode->getFname();
3612 funcNode->setFname(_funcName);
3617 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3621 catch (Exception& ex)
3623 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute() : " << ex.what());
3629 bool CommandSetFuncNodeFunctionName::localReverse()
3631 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse");
3634 Proc* proc = GuiContext::getCurrent()->getProc();
3635 Node* node = proc->getChildByName(_nodeName);
3636 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3638 funcNode->setFname(_oldName);
3643 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3647 catch (Exception& ex)
3649 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse() : " << ex.what());
3655 // ----------------------------------------------------------------------------
3657 CommandSetInlineNodeScript::CommandSetInlineNodeScript(std::string node, std::string script)
3658 : Command(), _nodeName(node), _script(script)
3660 DEBTRACE("CommandSetInlineNodeScript::CommandSetInlineNodeScript " << node << " " <<script);
3664 std::string CommandSetInlineNodeScript::dump()
3666 string ret ="CommandSetInlineNodeScript " + _nodeName;
3670 bool CommandSetInlineNodeScript::localExecute()
3672 DEBTRACE("CommandSetInlineNodeScript::localExecute");
3675 Proc* proc = GuiContext::getCurrent()->getProc();
3676 Node* node = proc->getChildByName(_nodeName);
3677 if (_script.empty())
3679 GuiContext::getCurrent()->_lastErrorMessage = "InlineNode script empty: " + _nodeName;
3682 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3684 _oldScript = inlineNode->getScript();
3685 inlineNode->setScript(_script);
3686 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3687 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3688 snode->update(SYNCHRO,0,snode);
3693 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3697 catch (Exception& ex)
3699 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3705 bool CommandSetInlineNodeScript::localReverse()
3707 DEBTRACE("CommandSetInlineNodeScript::localReverse");
3710 Proc* proc = GuiContext::getCurrent()->getProc();
3711 Node* node = proc->getChildByName(_nodeName);
3712 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3714 inlineNode->setScript(_oldScript);
3715 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3716 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3717 snode->update(SYNCHRO,0,snode);
3722 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3726 catch (Exception& ex)
3728 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3734 // ----------------------------------------------------------------------------
3736 CommandAddComponentInstance::CommandAddComponentInstance(std::string compoName,
3737 std::string container,
3739 : Command(), _compoName(compoName), _container(container), _name(name), _subcompo(0)
3741 DEBTRACE("CommandAddComponentInstance::CommandAddComponentInstance " <<_compoName);
3744 std::string CommandAddComponentInstance::dump()
3746 string ret ="CommandAddComponentInstance " + _compoName + " " + _container + " " + _name;
3750 bool CommandAddComponentInstance::localExecute()
3752 DEBTRACE("CommandAddComponentInstance::localExecute "<< _compoName << " " << _container << " " << _name);
3755 Proc* proc = GuiContext::getCurrent()->getProc();
3756 YASSERT(proc->containerMap.count(_container));
3757 Container *cont = proc->containerMap[_container];
3758 ComponentInstance* compoInst = new SalomeComponent(_compoName);
3759 compoInst->setContainer(cont);
3760 proc->addComponentInstance(compoInst, _name);
3762 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
3763 _subcompo = sproc->addSubjectComponent(compoInst);
3764 _name = compoInst->getInstanceName();
3768 catch (Exception& ex)
3770 DEBTRACE("CommandAddComponentInstance::localExecute() : " << ex.what());
3776 bool CommandAddComponentInstance::localReverse()
3778 DEBTRACE("CommandAddComponentInstance::localReverse");
3781 Proc* proc = GuiContext::getCurrent()->getProc();
3782 YASSERT(proc->componentInstanceMap.count(_name));
3783 ComponentInstance *compo = proc->componentInstanceMap[_name];
3784 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
3785 _subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
3786 YASSERT(!_subcompo->hasServices());
3787 Container *cont = compo->getContainer();
3788 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
3789 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3790 subcont->detachComponent(_subcompo);
3791 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
3792 proc->removeComponentInstance(compo);
3795 catch (Exception& ex)
3797 DEBTRACE("CommandAddComponentInstance::localReverse() : " << ex.what());
3803 // ----------------------------------------------------------------------------
3804 CommandSetExecutionMode::CommandSetExecutionMode(std::string nodeName, std::string mode)
3805 : Command(), _mode(mode),_nodeName(nodeName)
3807 DEBTRACE("CommandSetExecutionMode::CommandSetExecutionMode " << nodeName << " " << mode);
3811 std::string CommandSetExecutionMode::dump()
3813 string ret ="CommandSetExecutionMode " + _mode + " " + _nodeName;
3817 bool CommandSetExecutionMode::localExecute()
3819 DEBTRACE("CommandSetExecutionMode::localExecute");
3822 Proc* proc = GuiContext::getCurrent()->getProc();
3823 Node* node = proc->getChildByName(_nodeName);
3824 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3826 _oldmode = pyNode->getExecutionMode();
3827 pyNode->setExecutionMode(_mode);
3828 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3829 snode->update(UPDATE, 0, 0);
3834 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3838 catch (Exception& ex)
3840 DEBTRACE("CommandSetExecutionMode::localExecute() : " << ex.what());
3846 bool CommandSetExecutionMode::localReverse()
3848 DEBTRACE("CommandSetExecutionMode::localReverse");
3851 if (_oldmode == _mode) return true;
3852 Proc* proc = GuiContext::getCurrent()->getProc();
3853 Node* node = proc->getChildByName(_nodeName);
3854 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3856 pyNode->setExecutionMode(_oldmode);
3857 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3858 snode->update(UPDATE, 0, 0);
3863 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3867 catch (Exception& ex)
3869 DEBTRACE("CommandSetExecutionMode::localReverse() : " << ex.what());
3877 // ----------------------------------------------------------------------------
3879 CommandSetContainer::CommandSetContainer(std::string nodeName, std::string container)
3880 : Command(), _container(container),_nodeName(nodeName)
3882 DEBTRACE("CommandSetContainer::CommandSetContainer " << nodeName << " " << container);
3883 _oldcont = "DefaultContainer";
3886 std::string CommandSetContainer::dump()
3888 string ret ="CommandSetContainer " + _container + " " + _nodeName;
3892 bool CommandSetContainer::localExecute()
3894 DEBTRACE("CommandSetContainer::localExecute");
3897 Proc* proc = GuiContext::getCurrent()->getProc();
3898 if (proc->containerMap.count(_container))
3900 Container *cont = proc->containerMap[_container];
3901 Node* node = proc->getChildByName(_nodeName);
3902 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3904 Container* oldcont = pyNode->getContainer();
3906 _oldcont = pyNode->getContainer()->getName();
3907 pyNode->setContainer(cont);
3908 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3909 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3910 snode->update(ASSOCIATE, 0, subcont);
3915 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3920 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
3923 catch (Exception& ex)
3925 DEBTRACE("CommandSetContainer::localExecute() : " << ex.what());
3931 bool CommandSetContainer::localReverse()
3933 DEBTRACE("CommandSetContainer::localReverse");
3936 if (_oldcont == _container) return true;
3937 Proc* proc = GuiContext::getCurrent()->getProc();
3938 if (proc->containerMap.count(_oldcont))
3940 Container *cont = proc->containerMap[_oldcont];
3941 Node* node = proc->getChildByName(_nodeName);
3942 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3944 pyNode->setContainer(cont);
3945 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3946 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3947 snode->update(ASSOCIATE, 0, subcont);
3952 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3957 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
3960 catch (Exception& ex)
3962 DEBTRACE("CommandSetContainer::localReverse() : " << ex.what());
3971 // ----------------------------------------------------------------------------
3973 CommandAssociateComponentToContainer::CommandAssociateComponentToContainer(std::string instanceName,
3974 std::string container)
3975 : Command(), _container(container),_instanceName(instanceName)
3977 DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer " << instanceName << " " << container);
3978 _oldcont = "DefaultContainer";
3981 std::string CommandAssociateComponentToContainer::dump()
3983 string ret ="CommandAssociateComponentToContainer " + _container + " " + _instanceName;
3987 bool CommandAssociateComponentToContainer::localExecute()
3989 DEBTRACE("CommandAssociateComponentToContainer::localExecute");
3992 Proc* proc = GuiContext::getCurrent()->getProc();
3993 if (proc->containerMap.count(_container))
3995 Container *cont = proc->containerMap[_container];
3996 if (proc->componentInstanceMap.count(_instanceName))
3998 DEBTRACE(_instanceName);
3999 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4000 if (compo->getContainer())
4001 _oldcont = compo->getContainer()->getName();
4002 compo->setContainer(cont);
4004 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4005 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4006 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4007 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4008 scomp->addSubjectReference(subcont);
4009 if (scomp->_subRefContainer)
4010 subcont->moveComponent(scomp->_subRefContainer);
4012 scomp->_subRefContainer = subcont->attachComponent(scomp);
4013 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4017 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4020 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
4023 catch (Exception& ex)
4025 DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
4031 bool CommandAssociateComponentToContainer::localReverse()
4033 DEBTRACE("CommandAssociateComponentToContainer::localReverse");
4036 if (_oldcont == _container) return true;
4037 Proc* proc = GuiContext::getCurrent()->getProc();
4038 if (proc->containerMap.count(_oldcont))
4040 Container *cont = proc->containerMap[_oldcont];
4041 if (proc->componentInstanceMap.count(_instanceName))
4043 DEBTRACE(_instanceName);
4044 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4045 compo->setContainer(cont);
4047 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4048 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4049 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4050 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4051 scomp->addSubjectReference(subcont);
4052 if (scomp->_subRefContainer)
4053 subcont->moveComponent(scomp->_subRefContainer);
4055 scomp->_subRefContainer = subcont->attachComponent(scomp);
4056 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4060 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4063 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
4066 catch (Exception& ex)
4068 DEBTRACE("CommandAssociateComponentToContainer::localReverse() : " << ex.what());
4075 // ----------------------------------------------------------------------------
4077 CommandAssociateServiceToComponent::CommandAssociateServiceToComponent(std::string service,
4078 std::string instanceName)
4079 : Command(), _service(service), _instanceName(instanceName)
4081 DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4085 std::string CommandAssociateServiceToComponent::dump()
4087 string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4091 bool CommandAssociateServiceToComponent::localExecute()
4093 DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4096 Proc* proc = GuiContext::getCurrent()->getProc();
4097 if (_service == proc->getName()) return false; // proc is not an elementary node
4098 Node* node = proc->getChildByName(_service);
4099 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4101 if (proc->componentInstanceMap.count(_instanceName))
4103 DEBTRACE(_instanceName);
4104 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4105 service->setComponent(compo);
4107 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4108 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4109 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4111 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4112 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4113 snode->addSubjectReference(subCompo);
4114 if (ssnode->_subRefComponent)
4116 SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4118 _oldInstance = oldcomp->getName();
4119 _oldcont = oldcomp->getComponent()->getContainer()->getName();
4120 subCompo->moveService(ssnode->_subRefComponent);
4123 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4128 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4131 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4134 catch (Exception& ex)
4136 DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4142 bool CommandAssociateServiceToComponent::localReverse()
4144 DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4147 Proc* proc = GuiContext::getCurrent()->getProc();
4148 if (_service == proc->getName()) return false; // proc is not an elementary node
4149 Node* node = proc->getChildByName(_service);
4150 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4152 ComponentInstance *compo;
4153 if (!proc->componentInstanceMap.count(_oldInstance))
4155 //component instance does not exist anymore recreate it
4156 ComponentInstance *oldcompo = service->getComponent();
4157 compo = oldcompo->cloneAlways();
4158 compo->setName(_oldInstance);
4159 proc->addComponentInstance(compo, _oldInstance);
4160 Container *cont = proc->containerMap[_oldcont];
4161 compo->setContainer(cont);
4162 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
4163 sproc->addSubjectComponent(compo);
4167 compo = proc->componentInstanceMap[_oldInstance];
4170 DEBTRACE(_oldInstance);
4171 service->setComponent(compo);
4173 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4174 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4175 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4177 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4178 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4179 snode->addSubjectReference(subCompo);
4180 if (ssnode->_subRefComponent)
4181 subCompo->moveService(ssnode->_subRefComponent);
4183 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4188 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4191 catch (Exception& ex)
4193 DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4199 // ----------------------------------------------------------------------------
4201 CommandAddComponentFromCatalog::CommandAddComponentFromCatalog(YACS::ENGINE::Catalog* catalog,
4202 std::string position,
4204 std::string service)
4205 : Command(), _catalog(catalog), _position(position), _compo(compo), _service(service)
4207 DEBTRACE("CommandAddComponentFromCatalog::CommandAddComponentFromCatalog " << position << " " << compo << " " << service);
4209 _createdInstance = false;
4212 std::string CommandAddComponentFromCatalog::dump()
4214 string ret = "CommandAddComponentFromCatalog " + _position + " " + _compo + " " + _service;
4218 bool CommandAddComponentFromCatalog::localExecute()
4220 DEBTRACE("CommandAddComponentFromCatalog::localExecute");
4223 DEBTRACE("_nameInProc: " << _nameInProc);
4224 Proc* proc = GuiContext::getCurrent()->getProc();
4226 if (!_position.empty()) node = proc->getChildByName(_position);
4227 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4228 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4229 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4231 if (_catalog->_componentMap.count(_compo))
4233 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compo];
4234 if (compodef->_serviceMap.count(_service))
4236 Proc* proc = GuiContext::getCurrent()->getProc();
4237 ComponentInstance *instance =ssnode->_serviceNode->getComponent();
4239 SubjectComponent* subCompo = 0;
4240 _createdInstance = false;
4241 if(!GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
4243 _createdInstance = true;
4244 //automatic rename of the component instance by the proc on first execute
4245 DEBTRACE("name given to proc:" << _nameInProc);
4246 proc->addComponentInstance(instance,_nameInProc, true);
4247 _nameInProc= instance->getInstanceName();
4248 DEBTRACE("name given by proc:" << _nameInProc);
4249 subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
4252 subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
4254 ssnode->addSubjectReference(subCompo);
4255 YASSERT(! ssnode->_subRefComponent);
4256 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4261 catch (Exception& ex)
4263 DEBTRACE("CommandAddComponentFromCatalog::localExecute() : " << ex.what());
4269 bool CommandAddComponentFromCatalog::localReverse()
4271 DEBTRACE("CommandAddComponentFromCatalog::localReverse");
4274 Proc* proc = GuiContext::getCurrent()->getProc();
4276 if (!_position.empty()) node = proc->getChildByName(_position);
4277 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4278 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4279 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4282 DEBTRACE("_nameInProc: " << _nameInProc);
4283 YASSERT(proc->componentInstanceMap.count(_nameInProc));
4284 ComponentInstance *compo = proc->componentInstanceMap[_nameInProc];
4285 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4286 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4288 subCompo->detachService(ssnode);
4289 if (subCompo->hasServices())
4290 throw YACS::Exception("Component instance with services attached, not removed");
4291 Container *cont = compo->getContainer();
4292 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4293 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4294 subcont->detachComponent(subCompo);
4295 //remove componentInstance from proc, from context
4296 if (_createdInstance)
4298 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
4299 proc->removeComponentInstance(compo);
4301 DEBTRACE("_nameInProc: " << _nameInProc);
4304 catch (Exception& ex)
4306 DEBTRACE("CommandAddComponentFromCatalog::localReverse() : " << ex.what());