1 // Copyright (C) 2006-2019 CEA/DEN, EDF R&D
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::ForEachLoop*>(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::ForEachLoop*>(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());
2475 bool CommandSetSwitchSelect::localReverse()
2477 DEBTRACE("CommandSetSwitchSelect::localReverse");
2480 Proc* proc = GuiContext::getCurrent()->getProc();
2481 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2482 InputPort *condPort = aSwitch->edGetConditionPort();
2483 int val = atoi(_oldValue.c_str());
2484 condPort->edInit(val);
2485 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2486 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2487 snode->update(SETSELECT, 0, snode);
2489 catch (Exception& ex)
2491 DEBTRACE("CommandSetSwitchSelect::localReverse() : " << ex.what());
2497 // ----------------------------------------------------------------------------
2499 CommandSetSwitchCase::CommandSetSwitchCase(std::string aSwitch,
2502 : Command(), _switch(aSwitch), _node(node), _value(value)
2504 DEBTRACE("CommandSetSwitchCase::CommandSetSwitchCase");
2509 std::string CommandSetSwitchCase::dump()
2511 string ret ="CommandSetSwitchCase " + _switch + " " + _node + " " + _value;
2515 bool CommandSetSwitchCase::localExecute()
2517 DEBTRACE("CommandSetSwitchCase::localExecute");
2520 DEBTRACE("CommandSetSwitchCase::localExecute");
2521 Proc* proc = GuiContext::getCurrent()->getProc();
2522 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2523 Node* node = proc->getChildByName(_node);
2524 int val = atoi(_value.c_str());
2525 if (aSwitch->edGetNode(val))
2527 throw YACS::Exception("Set Switch Case impossible: value already used");
2529 int oldVal = aSwitch->getRankOfNode(node);
2530 aSwitch->edChangeCase(oldVal,val);
2532 _oldNode = proc->getChildName(node);
2533 DEBTRACE("CommandSetSwitchCase::localExecute OK " << val);
2534 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2535 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2536 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2537 ssw->update(SETCASE, val, snode);
2538 snode->recursiveUpdate(RENAME, 0, snode);
2541 catch (Exception& ex)
2543 DEBTRACE("CommandSetSwitchCase::localExecute() : " << ex.what());
2549 bool CommandSetSwitchCase::localReverse()
2551 DEBTRACE("CommandSetSwitchCase::localReverse");
2554 DEBTRACE("CommandSetSwitchCase::localReverse");
2555 Proc* proc = GuiContext::getCurrent()->getProc();
2556 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2557 Node* node = proc->getChildByName(_oldNode);
2558 int val = _oldValue;
2559 if (aSwitch->edGetNode(val))
2561 throw YACS::Exception("Set Switch Case impossible: value already used");
2563 int oldVal = aSwitch->getRankOfNode(node);
2564 aSwitch->edChangeCase(oldVal,val);
2565 DEBTRACE("CommandSetSwitchCase::localReverse OK " << val);
2566 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2567 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2568 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2569 ssw->update(SETCASE, val, snode);
2570 snode->recursiveUpdate(RENAME, 0, snode);
2573 catch (Exception& ex)
2575 DEBTRACE("CommandSetSwitchCase::localReverse() : " << ex.what());
2581 // ----------------------------------------------------------------------------
2583 CommandSetForLoopSteps::CommandSetForLoopSteps(std::string forLoop,
2585 : Command(), _forLoop(forLoop), _value(value)
2587 DEBTRACE("CommandSetForLoopSteps::CommandSetForLoopSteps");
2592 std::string CommandSetForLoopSteps::dump()
2594 string ret ="CommandSetForLoopSteps " + _forLoop + " " + _value;
2598 bool CommandSetForLoopSteps::localExecute()
2600 DEBTRACE("CommandSetForLoopSteps::localExecute");
2603 DEBTRACE("CommandSetForLoopSteps::localExecute");
2604 Proc* proc = GuiContext::getCurrent()->getProc();
2605 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2606 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2607 _oldValue = atoi(forLoop->edGetNbOfTimesInputPort()->getAsString().c_str());
2608 int val = atoi(_value.c_str());
2609 nbSteps->edInit(val);
2610 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2611 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2612 snode->update(SETVALUE, 0, snode);
2615 catch (Exception& ex)
2617 DEBTRACE("CommandSetForLoopSteps::localExecute() : " << ex.what());
2623 bool CommandSetForLoopSteps::localReverse()
2625 DEBTRACE("CommandSetForLoopSteps::localReverse");
2628 DEBTRACE("CommandSetForLoopSteps::localReverse");
2629 Proc* proc = GuiContext::getCurrent()->getProc();
2630 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2631 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2632 nbSteps->edInit(_oldValue);
2633 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2634 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2635 snode->update(SETVALUE, 0, snode);
2638 catch (Exception& ex)
2640 DEBTRACE("CommandSetForLoopSteps::localReverse() : " << ex.what());
2646 // ----------------------------------------------------------------------------
2648 CommandSetWhileCondition::CommandSetWhileCondition(std::string whileLoop,
2650 : Command(), _whileLoop(whileLoop), _value(value)
2652 DEBTRACE("CommandSetWhileCondition::CommandSetWhileCondition");
2656 std::string CommandSetWhileCondition::dump()
2658 string ret ="CommandSetWhileCondition " + _whileLoop + " " + _value;
2662 bool CommandSetWhileCondition::localExecute()
2664 DEBTRACE("CommandSetWhileCondition::localExecute");
2667 Proc* proc = GuiContext::getCurrent()->getProc();
2668 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2669 InputPort *cond = whileLoop->edGetConditionPort();
2670 _oldValue = atoi(whileLoop->edGetConditionPort()->getAsString().c_str());
2671 bool val = atoi(_value.c_str());
2673 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2674 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2675 snode->update(SETVALUE, 0, snode);
2678 catch (Exception& ex)
2680 DEBTRACE("CommandSetWhileCondition::localExecute() : " << ex.what());
2686 bool CommandSetWhileCondition::localReverse()
2688 DEBTRACE("CommandSetWhileCondition::localReverse");
2691 Proc* proc = GuiContext::getCurrent()->getProc();
2692 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2693 InputPort *cond = whileLoop->edGetConditionPort();
2694 cond->edInit(_oldValue);
2695 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2696 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2697 snode->update(SETVALUE, 0, snode);
2700 catch (Exception& ex)
2702 DEBTRACE("CommandSetWhileCondition::localReverse() : " << ex.what());
2708 // ----------------------------------------------------------------------------
2710 CommandSetForEachBranch::CommandSetForEachBranch(std::string forEach,
2712 : Command(), _forEach(forEach), _value(value)
2714 DEBTRACE("CommandSetForEachBranch::CommandSetForEachBranch");
2718 std::string CommandSetForEachBranch::dump()
2720 string ret ="CommandSetForEachBranch " + _forEach + " " + _value;
2724 bool CommandSetForEachBranch::localExecute()
2726 DEBTRACE("CommandSetForEachBranch::localExecute");
2729 Proc* proc = GuiContext::getCurrent()->getProc();
2730 Node* node=proc->getChildByName(_forEach);
2731 InputPort *nbBranches = node->getInputPort("nbBranches");
2732 _oldValue = atoi(nbBranches->getAsString().c_str());
2733 int val = atoi(_value.c_str());
2734 nbBranches->edInit(val);
2735 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2736 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2737 spo->update(SETVALUE, 0, spo);
2738 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2739 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2740 snode->update(SETVALUE, 0, snode);
2743 catch (Exception& ex)
2745 DEBTRACE("CommandSetForEachBranch::localExecute() : " << ex.what());
2751 bool CommandSetForEachBranch::localReverse()
2753 DEBTRACE("CommandSetForEachBranch::localReverse");
2756 Proc* proc = GuiContext::getCurrent()->getProc();
2757 Node* node=proc->getChildByName(_forEach);
2758 InputPort *nbBranches = node->getInputPort("nbBranches");
2759 nbBranches->edInit(_oldValue);
2760 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2761 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2762 spo->update(SETVALUE, 0, spo);
2763 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2764 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2765 snode->update(SETVALUE, 0, snode);
2768 catch (Exception& ex)
2770 DEBTRACE("CommandSetForEachBranch::localReverse() : " << ex.what());
2776 // ----------------------------------------------------------------------------
2778 CommandSetAlgo::CommandSetAlgo(std::string optimizer, std::string alglib, std::string symbol)
2779 : Command(), _optimizer(optimizer), _alglib(alglib), _symbol(symbol)
2781 DEBTRACE("CommandSetAlgo::CommandSetAlgo" << _optimizer << " " << _alglib << " " << _symbol);
2786 std::string CommandSetAlgo::dump()
2788 string ret ="CommandSetAlgo " + _optimizer + " " + _alglib + " " + _symbol;
2792 bool CommandSetAlgo::localExecute()
2794 DEBTRACE("CommandSetAlgo::localExecute");
2797 Proc* proc = GuiContext::getCurrent()->getProc();
2798 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2799 loop->setAlgorithm(_alglib,_symbol);
2800 _oldAlglib = _alglib;
2801 _oldSymbol = _symbol;
2802 InputPort *port = loop->edGetPortForOutPool();
2803 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2804 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2805 spo->update(UPDATE, 0, spo);
2806 OutputPort *oport = loop->edGetSamplePort();
2807 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2808 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2809 spo->update(UPDATE, 0, spo);
2810 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2811 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2812 snode->update(SETVALUE, 0, snode);
2815 catch (Exception& ex)
2817 DEBTRACE("CommandSetAlgo::localExecute() : " << ex.what());
2823 bool CommandSetAlgo::localReverse()
2825 DEBTRACE("CommandSetAlgo::localReverse");
2828 Proc* proc = GuiContext::getCurrent()->getProc();
2829 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2830 loop->setAlgorithm(_oldAlglib,_oldSymbol);
2831 InputPort *port = loop->edGetPortForOutPool();
2832 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2833 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2834 spo->update(UPDATE, 0, spo);
2835 OutputPort *oport = loop->edGetSamplePort();
2836 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2837 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2838 spo->update(UPDATE, 0, spo);
2839 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2840 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2841 snode->update(SETVALUE, 0, snode);
2844 catch (Exception& ex)
2846 DEBTRACE("CommandSetAlgo::localReverse() : " << ex.what());
2853 // ----------------------------------------------------------------------------
2855 CommandAddLink::CommandAddLink(std::string outNode, std::string outPort, TypeOfElem outPortType,
2856 std::string inNode, std::string inPort, TypeOfElem inPortType, bool control)
2857 : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2858 _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2860 DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2861 _controlCreatedWithDF = false;
2864 std::string CommandAddLink::dump()
2867 if (_control) s = "true";
2868 string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2872 bool CommandAddLink::localExecute()
2874 DEBTRACE("CommandAddLink::localExecute");
2875 DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2878 Proc* proc = GuiContext::getCurrent()->getProc();
2879 Node* outn = proc->getChildByName(_outNode);
2880 Node* inn = proc->getChildByName(_inNode);
2884 // --- is a control link already existing ?
2885 bool preexistingControl = false;
2889 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2890 if(outn2==father || inn2==father)
2891 preexistingControl = true;
2894 while(outn2->getFather() != father)
2895 outn2 = outn2->getFather();
2896 while(inn2->getFather() != father)
2897 inn2 = inn2->getFather();
2898 OutGate *ogate = outn2->getOutGate();
2899 InGate *igate = inn2->getInGate();
2900 if (ogate->isAlreadyInSet(igate))
2901 preexistingControl = true;
2905 if(_outPortType == OUTPUTPORT)
2906 outp = outn->getOutputPort(_outPort);
2908 outp = outn->getOutputDataStreamPort(_outPort);
2910 if(_inPortType == INPUTPORT)
2911 inp = inn->getInputPort(_inPort);
2913 inp = inn->getInputDataStreamPort(_inPort);
2915 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2916 DEBTRACE(cla->getName());
2917 if (dynamic_cast<OutputDataStreamPort*>(outp))
2918 cla->edAddLink(outp,inp);
2920 cla->edAddDFLink(outp,inp);
2922 cla->edAddLink(outp,inp);
2924 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2925 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
2926 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2927 DEBTRACE(scla->getName());
2928 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2929 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2930 SubjectDataPort *subOutport = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2931 SubjectDataPort *subInport = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2932 SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2934 // --- if control link, identify the nodes linked and draw the control link if not already existing
2938 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2939 if(outn==father || inn==father) return true;
2940 while(outn->getFather() != father)
2941 outn = outn->getFather();
2942 while(inn->getFather() != father)
2943 inn = inn->getFather();
2944 OutGate *ogate = outn->getOutGate();
2945 InGate *igate = inn->getInGate();
2946 if (ogate->isAlreadyInSet(igate))
2948 if (!preexistingControl)
2949 _controlCreatedWithDF = true;
2950 pair<Node*,Node*> keyLink(outn,inn);
2951 if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2953 SubjectNode *sfno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2954 SubjectNode *sfni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2955 if (!sfno || !sfni) return true;
2956 SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2962 catch (Exception& ex)
2964 DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2970 bool CommandAddLink::localReverse()
2972 DEBTRACE("CommandAddLink::localReverse");
2975 SubjectLink *slink =0;
2976 SubjectControlLink *sclink = 0;
2977 Proc* proc = GuiContext::getCurrent()->getProc();
2978 Node* outn = proc->getChildByName(_outNode);
2979 Node* inn = proc->getChildByName(_inNode);
2982 if(_outPortType == OUTPUTPORT)
2983 outp = outn->getOutputPort(_outPort);
2985 outp = outn->getOutputDataStreamPort(_outPort);
2986 if(_inPortType == INPUTPORT)
2987 inp = inn->getInputPort(_inPort);
2989 inp = inn->getInputDataStreamPort(_inPort);
2990 YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(pair<OutPort*,InPort*>(outp,inp)));
2991 slink = GuiContext::getCurrent()->_mapOfSubjectLink[pair<OutPort*,InPort*>(outp,inp)];
2992 if (_controlCreatedWithDF)
2994 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
2995 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
2998 Subject *father = slink->getParent();
2999 Subject::erase(slink);
3004 father->select(true);
3005 father->update(REMOVE,0,0);
3009 father=sclink->getParent();
3010 Subject::erase(sclink);
3015 father->select(true);
3016 father->update(REMOVE,0,0);
3020 catch (Exception& ex)
3022 DEBTRACE("CommandAddLink::localReverse(): " << ex.what());
3028 // ----------------------------------------------------------------------------
3030 CommandAddControlLink::CommandAddControlLink(std::string outNode, std::string inNode)
3031 : Command(), _outNode(outNode), _inNode(inNode)
3033 DEBTRACE("CommandAddControlLink::CommandAddControlLink "<<outNode<<"-->>"<<inNode);
3036 std::string CommandAddControlLink::dump()
3038 string ret ="CommandAddControlLink " + _outNode + " " + _inNode;
3042 bool CommandAddControlLink::localExecute()
3044 DEBTRACE("CommandAddControlLink::localExecute");
3047 Proc* proc = GuiContext::getCurrent()->getProc();
3049 if (! _outNode.empty())
3050 outn = proc->getChildByName(_outNode);
3052 if (! _inNode.empty())
3053 inn = proc->getChildByName(_inNode);
3054 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn,inn);
3055 DEBTRACE(cla->getName());
3056 bool ret= cla->edAddCFLink(outn,inn);
3058 GuiContext::getCurrent()->_lastErrorMessage = "Link already exists";
3060 cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),
3062 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
3063 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
3064 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
3065 DEBTRACE(scla->getName());
3066 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
3067 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
3068 SubjectControlLink *sclink = scla->addSubjectControlLink(sno,sni);
3071 catch (Exception& ex)
3073 DEBTRACE("CommandAddControlLink::localExecute() : " << ex.what());
3079 bool CommandAddControlLink::localReverse()
3081 DEBTRACE("CommandAddControlLink::localReverse");
3084 SubjectControlLink *sclink = 0;
3085 Proc* proc = GuiContext::getCurrent()->getProc();
3086 Node* outn = proc->getChildByName(_outNode);
3087 Node* inn = proc->getChildByName(_inNode);
3088 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
3089 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
3091 Subject *father=sclink->getParent();
3092 Subject::erase(sclink);
3097 father->select(true);
3098 father->update(REMOVE,0,0);
3102 catch (Exception& ex)
3104 DEBTRACE("CommandAddControlLink::localReverse(): " << ex.what());
3110 // ----------------------------------------------------------------------------
3112 CommandAddContainerBase::CommandAddContainerBase(std::string name, std::string refContainer)
3113 : Command(), _name(name), _containerToClone(refContainer), _subcont(0)
3115 DEBTRACE("CommandAddContainerBase::CommandAddContainerBase " << name << " " << refContainer);
3118 CommandAddContainerBase::~CommandAddContainerBase()
3122 bool CommandAddContainerBase::localExecute()
3124 DEBTRACE("CommandAddContainerBase::localExecute");
3127 Proc* proc = GuiContext::getCurrent()->getProc();
3128 if (proc->containerMap.count(_name))
3130 GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
3133 Container *container(createNewInstance());
3134 if (! _containerToClone.empty())
3136 if (proc->containerMap.count(_containerToClone))
3138 Container *ref = proc->containerMap[_containerToClone];
3140 container->setProperties(ref->getProperties());
3144 GuiContext::getCurrent()->_lastErrorMessage = "There is no reference container to clone properties";
3148 container->setName(_name);
3149 container->setProc(proc);
3150 proc->containerMap[_name] = container;
3152 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3153 _subcont = sproc->addSubjectContainer(container, _name);
3156 catch (Exception& ex)
3158 DEBTRACE("CommandAddContainerBase::localExecute() : " << ex.what());
3164 bool CommandAddContainerBase::localReverse()
3166 DEBTRACE("CommandAddContainerBase::localReverse");
3169 Proc* proc = GuiContext::getCurrent()->getProc();
3170 YASSERT(proc->containerMap.count(_name));
3171 Container *container = proc->containerMap[_name];
3172 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
3173 _subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
3174 YASSERT(!_subcont->isUsed());
3175 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3176 sproc->removeSubjectContainer(_subcont);
3179 catch (Exception& ex)
3181 DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
3187 // ----------------------------------------------------------------------------
3189 CommandAddContainer::CommandAddContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3193 std::string CommandAddContainer::dump()
3195 string ret ="CommandAddContainer " + _name + " " + _containerToClone;
3199 Container *CommandAddContainer::createNewInstance() const
3201 return new SalomeContainer;
3204 // ----------------------------------------------------------------------------
3206 CommandAddHPContainer::CommandAddHPContainer(std::string name, std::string refContainer):CommandAddContainerBase(name,refContainer)
3210 std::string CommandAddHPContainer::dump()
3212 string ret ="CommandAddHPContainer " + _name + " " + _containerToClone;
3216 Container *CommandAddHPContainer::createNewInstance() const
3218 return new SalomeHPContainer;
3221 // ----------------------------------------------------------------------------
3223 CommandSetNodeProperties::CommandSetNodeProperties(std::string position, std::map<std::string,std::string> properties)
3224 : Command(), _position(position), _properties(properties)
3226 DEBTRACE("CommandSetNodeProperties::CommandSetNodeProperties " << position);
3230 std::string CommandSetNodeProperties::dump()
3232 string ret ="CommandSetNodeProperties " + _position;
3236 bool CommandSetNodeProperties::localExecute()
3238 DEBTRACE("CommandSetNodeProperties::localExecute");
3241 Proc* proc = GuiContext::getCurrent()->getProc();
3244 if (!_position.empty()) node = proc->getChildByName(_position);
3248 _oldProp = node->getPropertyMap();
3249 node->setProperties(_properties);
3250 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3251 snode->update(SETVALUE, 0, snode);
3254 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3257 catch (Exception& ex)
3259 DEBTRACE("CommandSetNodeProperties::localExecute() : " << ex.what());
3265 bool CommandSetNodeProperties::localReverse()
3267 DEBTRACE("CommandSetNodeProperties::localReverse");
3270 Proc* proc = GuiContext::getCurrent()->getProc();
3273 if (!_position.empty()) node = proc->getChildByName(_position);
3277 node->setProperties(_oldProp);
3278 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3279 snode->update(SETVALUE, 0, snode);
3282 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3285 catch (Exception& ex)
3287 DEBTRACE("CommandSetNodeProperties::localReverse() : " << ex.what());
3293 // ----------------------------------------------------------------------------
3295 CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties(std::string compoinstance,
3296 std::map<std::string,std::string> properties)
3297 : Command(), _compoinstance(compoinstance), _properties(properties)
3299 DEBTRACE("CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties " << compoinstance);
3303 std::string CommandSetComponentInstanceProperties::dump()
3305 string ret ="CommandSetComponentInstanceProperties " + _compoinstance;
3309 bool CommandSetComponentInstanceProperties::localExecute()
3311 DEBTRACE("CommandSetComponentInstanceProperties::localExecute");
3314 Proc* proc = GuiContext::getCurrent()->getProc();
3315 if (proc->componentInstanceMap.count(_compoinstance))
3317 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3319 _oldProp = ref->getProperties();
3320 _oldAnon = ref->isAnonymous();
3321 ref->setProperties(_properties);
3322 ref->setAnonymous(false);
3323 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3324 subcompo->update(SETVALUE, 0, subcompo);
3327 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3330 catch (Exception& ex)
3332 DEBTRACE("CommandSetComponentInstanceProperties::localExecute() : " << ex.what());
3338 bool CommandSetComponentInstanceProperties::localReverse()
3340 DEBTRACE("CommandSetComponentInstanceProperties::localReverse");
3343 Proc* proc = GuiContext::getCurrent()->getProc();
3344 if (proc->componentInstanceMap.count(_compoinstance))
3346 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3348 ref->setProperties(_oldProp);
3349 ref->setAnonymous(_oldAnon);
3350 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3351 subcompo->update(SETVALUE, 0, subcompo);
3354 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3357 catch (Exception& ex)
3359 DEBTRACE("CommandSetComponentInstanceProperties::localReverse() : " << ex.what());
3365 // ----------------------------------------------------------------------------
3367 CommandSetContainerProperties::CommandSetContainerProperties(std::string container,
3368 std::map<std::string,std::string> properties)
3369 : Command(), _container(container), _properties(properties)
3371 DEBTRACE("CommandSetContainerProperties::CommandSetContainerProperties " << container);
3375 std::string CommandSetContainerProperties::dump()
3377 string ret ="CommandSetContainerProperties " + _container;
3381 bool CommandSetContainerProperties::localExecute()
3383 DEBTRACE("CommandSetContainerProperties::localExecute");
3386 Proc* proc = GuiContext::getCurrent()->getProc();
3387 if (proc->containerMap.count(_container))
3389 Container *ref(proc->containerMap[_container]);
3391 _oldProp = ref->getProperties();
3392 ref->setProperties(_properties);
3393 SubjectContainerBase *scont(GuiContext::getCurrent()->_mapOfSubjectContainer[ref]);
3394 scont->update(UPDATE, 0, scont);
3395 scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
3398 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3401 catch (Exception& ex)
3403 DEBTRACE("CommandSetContainerProperties::localExecute() : " << ex.what());
3409 bool CommandSetContainerProperties::localReverse()
3411 DEBTRACE("CommandSetContainerProperties::localReverse");
3414 Proc* proc = GuiContext::getCurrent()->getProc();
3415 if (proc->containerMap.count(_container))
3417 Container *ref = proc->containerMap[_container];
3419 ref->setProperties(_oldProp);
3422 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3425 catch (Exception& ex)
3427 DEBTRACE("CommandSetContainerProperties::localReverse() : " << ex.what());
3433 // ----------------------------------------------------------------------------
3435 CommandSetDSPortProperties::CommandSetDSPortProperties(std::string node, std::string port, bool isInport,
3436 std::map<std::string,std::string> properties)
3437 : Command(), _nodeName(node), _portName(port), _isInport(isInport), _properties(properties)
3439 DEBTRACE("CommandSetDSPortProperties::CommandSetDSPortProperties " << node << "." << port << " " << isInport);
3443 std::string CommandSetDSPortProperties::dump()
3446 if (_isInport) s = "true";
3447 string ret ="CommandSetDSPortProperties " + _nodeName + " " + _portName + " " + s;
3451 bool CommandSetDSPortProperties::localExecute()
3453 DEBTRACE("CommandSetDSPortProperties::localExecute");
3456 Proc* proc = GuiContext::getCurrent()->getProc();
3457 Node* node = proc->getChildByName(_nodeName);
3458 DataStreamPort* DSPort = 0;
3460 DSPort = node->getInputDataStreamPort(_portName);
3462 DSPort = node->getOutputDataStreamPort(_portName);
3463 _oldProp = DSPort->getProperties();
3464 DSPort->setProperties(_properties);
3467 catch (Exception& ex)
3469 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3475 bool CommandSetDSPortProperties::localReverse()
3477 DEBTRACE("CommandSetDSPortProperties::localReverse");
3480 Proc* proc = GuiContext::getCurrent()->getProc();
3481 Node* node = proc->getChildByName(_nodeName);
3482 DataStreamPort* DSPort = 0;
3484 DSPort = node->getInputDataStreamPort(_portName);
3486 DSPort = node->getOutputDataStreamPort(_portName);
3487 DSPort->setProperties(_oldProp);
3490 catch (Exception& ex)
3492 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3498 // ----------------------------------------------------------------------------
3500 CommandSetLinkProperties::CommandSetLinkProperties(std::string startnode, std::string startport,
3501 std::string endnode, std::string endport,
3502 std::map<std::string,std::string> properties)
3503 : Command(), _startNodeName(startnode), _startPortName(startport),
3504 _endNodeName(endnode), _endPortName(endport),
3505 _properties(properties)
3507 DEBTRACE("CommandSetLinkProperties::CommandSetLinkProperties " );
3511 std::string CommandSetLinkProperties::dump()
3513 string ret ="CommandSetLinkProperties " + _startNodeName + " " + _startPortName + " " + _endNodeName + " " + _endPortName;
3517 bool CommandSetLinkProperties::localExecute()
3519 DEBTRACE("CommandSetLinkProperties::localExecute");
3522 Proc* proc = GuiContext::getCurrent()->getProc();
3524 InputDataStreamPort* inDSPort = 0;
3525 OutputDataStreamPort* outDSPort = 0;
3527 node = proc->getChildByName(_startNodeName);
3528 outDSPort = node->getOutputDataStreamPort(_startPortName);
3529 outDSPort->setProperties(_properties);
3531 node = proc->getChildByName(_endNodeName);
3532 inDSPort = node->getInputDataStreamPort(_endPortName);
3533 _oldProp = inDSPort->getProperties();
3534 inDSPort->setProperties(_properties);
3536 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3537 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3538 subject->update(SETVALUE, 0, subject);
3541 catch (Exception& ex)
3543 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3549 bool CommandSetLinkProperties::localReverse()
3551 DEBTRACE("CommandSetLinkProperties::localReverse");
3554 Proc* proc = GuiContext::getCurrent()->getProc();
3556 InputDataStreamPort* inDSPort = 0;
3557 OutputDataStreamPort* outDSPort = 0;
3559 node = proc->getChildByName(_startNodeName);
3560 outDSPort = node->getOutputDataStreamPort(_startPortName);
3561 outDSPort->setProperties(_properties);
3563 node = proc->getChildByName(_endNodeName);
3564 inDSPort = node->getInputDataStreamPort(_endPortName);
3565 inDSPort->setProperties(_oldProp);
3567 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3568 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3569 subject->update(SETVALUE, 0, subject);
3572 catch (Exception& ex)
3574 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3580 // ----------------------------------------------------------------------------
3582 CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName(std::string node, std::string funcName)
3583 : Command(), _nodeName(node), _funcName(funcName)
3585 DEBTRACE("CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName " << node << " " <<funcName);
3589 std::string CommandSetFuncNodeFunctionName::dump()
3591 string ret ="CommandSetFuncNodeFunctionName " + _nodeName + " " + _funcName;
3595 bool CommandSetFuncNodeFunctionName::localExecute()
3597 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute");
3600 Proc* proc = GuiContext::getCurrent()->getProc();
3601 Node* node = proc->getChildByName(_nodeName);
3602 if (_funcName.empty())
3604 GuiContext::getCurrent()->_lastErrorMessage = "InlineFuncNode function name empty: " + _nodeName;
3607 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3609 _oldName = funcNode->getFname();
3610 funcNode->setFname(_funcName);
3615 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3619 catch (Exception& ex)
3621 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute() : " << ex.what());
3627 bool CommandSetFuncNodeFunctionName::localReverse()
3629 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse");
3632 Proc* proc = GuiContext::getCurrent()->getProc();
3633 Node* node = proc->getChildByName(_nodeName);
3634 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3636 funcNode->setFname(_oldName);
3641 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3645 catch (Exception& ex)
3647 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse() : " << ex.what());
3653 // ----------------------------------------------------------------------------
3655 CommandSetInlineNodeScript::CommandSetInlineNodeScript(std::string node, std::string script)
3656 : Command(), _nodeName(node), _script(script)
3658 DEBTRACE("CommandSetInlineNodeScript::CommandSetInlineNodeScript " << node << " " <<script);
3662 std::string CommandSetInlineNodeScript::dump()
3664 string ret ="CommandSetInlineNodeScript " + _nodeName;
3668 bool CommandSetInlineNodeScript::localExecute()
3670 DEBTRACE("CommandSetInlineNodeScript::localExecute");
3673 Proc* proc = GuiContext::getCurrent()->getProc();
3674 Node* node = proc->getChildByName(_nodeName);
3675 if (_script.empty())
3677 GuiContext::getCurrent()->_lastErrorMessage = "InlineNode script empty: " + _nodeName;
3680 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3682 _oldScript = inlineNode->getScript();
3683 inlineNode->setScript(_script);
3684 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3685 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3686 snode->update(SYNCHRO,0,snode);
3691 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3695 catch (Exception& ex)
3697 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3703 bool CommandSetInlineNodeScript::localReverse()
3705 DEBTRACE("CommandSetInlineNodeScript::localReverse");
3708 Proc* proc = GuiContext::getCurrent()->getProc();
3709 Node* node = proc->getChildByName(_nodeName);
3710 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3712 inlineNode->setScript(_oldScript);
3713 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3714 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3715 snode->update(SYNCHRO,0,snode);
3720 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3724 catch (Exception& ex)
3726 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3732 // ----------------------------------------------------------------------------
3734 CommandAddComponentInstance::CommandAddComponentInstance(std::string compoName,
3735 std::string container,
3737 : Command(), _compoName(compoName), _container(container), _name(name), _subcompo(0)
3739 DEBTRACE("CommandAddComponentInstance::CommandAddComponentInstance " <<_compoName);
3742 std::string CommandAddComponentInstance::dump()
3744 string ret ="CommandAddComponentInstance " + _compoName + " " + _container + " " + _name;
3748 bool CommandAddComponentInstance::localExecute()
3750 DEBTRACE("CommandAddComponentInstance::localExecute "<< _compoName << " " << _container << " " << _name);
3753 Proc* proc = GuiContext::getCurrent()->getProc();
3754 YASSERT(proc->containerMap.count(_container));
3755 Container *cont = proc->containerMap[_container];
3756 ComponentInstance* compoInst = new SalomeComponent(_compoName);
3757 compoInst->setContainer(cont);
3758 proc->addComponentInstance(compoInst, _name);
3760 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
3761 _subcompo = sproc->addSubjectComponent(compoInst);
3762 _name = compoInst->getInstanceName();
3766 catch (Exception& ex)
3768 DEBTRACE("CommandAddComponentInstance::localExecute() : " << ex.what());
3774 bool CommandAddComponentInstance::localReverse()
3776 DEBTRACE("CommandAddComponentInstance::localReverse");
3779 Proc* proc = GuiContext::getCurrent()->getProc();
3780 YASSERT(proc->componentInstanceMap.count(_name));
3781 ComponentInstance *compo = proc->componentInstanceMap[_name];
3782 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
3783 _subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
3784 YASSERT(!_subcompo->hasServices());
3785 Container *cont = compo->getContainer();
3786 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
3787 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3788 subcont->detachComponent(_subcompo);
3789 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
3790 proc->removeComponentInstance(compo);
3793 catch (Exception& ex)
3795 DEBTRACE("CommandAddComponentInstance::localReverse() : " << ex.what());
3801 // ----------------------------------------------------------------------------
3802 CommandSetExecutionMode::CommandSetExecutionMode(std::string nodeName, std::string mode)
3803 : Command(), _mode(mode),_nodeName(nodeName)
3805 DEBTRACE("CommandSetExecutionMode::CommandSetExecutionMode " << nodeName << " " << mode);
3809 std::string CommandSetExecutionMode::dump()
3811 string ret ="CommandSetExecutionMode " + _mode + " " + _nodeName;
3815 bool CommandSetExecutionMode::localExecute()
3817 DEBTRACE("CommandSetExecutionMode::localExecute");
3820 Proc* proc = GuiContext::getCurrent()->getProc();
3821 Node* node = proc->getChildByName(_nodeName);
3822 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3824 _oldmode = pyNode->getExecutionMode();
3825 pyNode->setExecutionMode(_mode);
3826 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3827 snode->update(UPDATE, 0, 0);
3832 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3836 catch (Exception& ex)
3838 DEBTRACE("CommandSetExecutionMode::localExecute() : " << ex.what());
3844 bool CommandSetExecutionMode::localReverse()
3846 DEBTRACE("CommandSetExecutionMode::localReverse");
3849 if (_oldmode == _mode) return true;
3850 Proc* proc = GuiContext::getCurrent()->getProc();
3851 Node* node = proc->getChildByName(_nodeName);
3852 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3854 pyNode->setExecutionMode(_oldmode);
3855 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3856 snode->update(UPDATE, 0, 0);
3861 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3865 catch (Exception& ex)
3867 DEBTRACE("CommandSetExecutionMode::localReverse() : " << ex.what());
3875 // ----------------------------------------------------------------------------
3877 CommandSetContainer::CommandSetContainer(std::string nodeName, std::string container)
3878 : Command(), _container(container),_nodeName(nodeName)
3880 DEBTRACE("CommandSetContainer::CommandSetContainer " << nodeName << " " << container);
3881 _oldcont = "DefaultContainer";
3884 std::string CommandSetContainer::dump()
3886 string ret ="CommandSetContainer " + _container + " " + _nodeName;
3890 bool CommandSetContainer::localExecute()
3892 DEBTRACE("CommandSetContainer::localExecute");
3895 Proc* proc = GuiContext::getCurrent()->getProc();
3896 if (proc->containerMap.count(_container))
3898 Container *cont = proc->containerMap[_container];
3899 Node* node = proc->getChildByName(_nodeName);
3900 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3902 Container* oldcont = pyNode->getContainer();
3904 _oldcont = pyNode->getContainer()->getName();
3905 pyNode->setContainer(cont);
3906 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3907 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3908 snode->update(ASSOCIATE, 0, subcont);
3913 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3918 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
3921 catch (Exception& ex)
3923 DEBTRACE("CommandSetContainer::localExecute() : " << ex.what());
3929 bool CommandSetContainer::localReverse()
3931 DEBTRACE("CommandSetContainer::localReverse");
3934 if (_oldcont == _container) return true;
3935 Proc* proc = GuiContext::getCurrent()->getProc();
3936 if (proc->containerMap.count(_oldcont))
3938 Container *cont = proc->containerMap[_oldcont];
3939 Node* node = proc->getChildByName(_nodeName);
3940 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3942 pyNode->setContainer(cont);
3943 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3944 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3945 snode->update(ASSOCIATE, 0, subcont);
3950 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3955 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
3958 catch (Exception& ex)
3960 DEBTRACE("CommandSetContainer::localReverse() : " << ex.what());
3969 // ----------------------------------------------------------------------------
3971 CommandAssociateComponentToContainer::CommandAssociateComponentToContainer(std::string instanceName,
3972 std::string container)
3973 : Command(), _container(container),_instanceName(instanceName)
3975 DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer " << instanceName << " " << container);
3976 _oldcont = "DefaultContainer";
3979 std::string CommandAssociateComponentToContainer::dump()
3981 string ret ="CommandAssociateComponentToContainer " + _container + " " + _instanceName;
3985 bool CommandAssociateComponentToContainer::localExecute()
3987 DEBTRACE("CommandAssociateComponentToContainer::localExecute");
3990 Proc* proc = GuiContext::getCurrent()->getProc();
3991 if (proc->containerMap.count(_container))
3993 Container *cont = proc->containerMap[_container];
3994 if (proc->componentInstanceMap.count(_instanceName))
3996 DEBTRACE(_instanceName);
3997 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
3998 if (compo->getContainer())
3999 _oldcont = compo->getContainer()->getName();
4000 compo->setContainer(cont);
4002 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4003 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4004 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4005 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4006 scomp->addSubjectReference(subcont);
4007 if (scomp->_subRefContainer)
4008 subcont->moveComponent(scomp->_subRefContainer);
4010 scomp->_subRefContainer = subcont->attachComponent(scomp);
4011 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4015 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4018 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
4021 catch (Exception& ex)
4023 DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
4029 bool CommandAssociateComponentToContainer::localReverse()
4031 DEBTRACE("CommandAssociateComponentToContainer::localReverse");
4034 if (_oldcont == _container) return true;
4035 Proc* proc = GuiContext::getCurrent()->getProc();
4036 if (proc->containerMap.count(_oldcont))
4038 Container *cont = proc->containerMap[_oldcont];
4039 if (proc->componentInstanceMap.count(_instanceName))
4041 DEBTRACE(_instanceName);
4042 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4043 compo->setContainer(cont);
4045 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4046 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4047 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4048 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4049 scomp->addSubjectReference(subcont);
4050 if (scomp->_subRefContainer)
4051 subcont->moveComponent(scomp->_subRefContainer);
4053 scomp->_subRefContainer = subcont->attachComponent(scomp);
4054 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4058 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4061 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
4064 catch (Exception& ex)
4066 DEBTRACE("CommandAssociateComponentToContainer::localReverse() : " << ex.what());
4073 // ----------------------------------------------------------------------------
4075 CommandAssociateServiceToComponent::CommandAssociateServiceToComponent(std::string service,
4076 std::string instanceName)
4077 : Command(), _service(service), _instanceName(instanceName)
4079 DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4083 std::string CommandAssociateServiceToComponent::dump()
4085 string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4089 bool CommandAssociateServiceToComponent::localExecute()
4091 DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4094 Proc* proc = GuiContext::getCurrent()->getProc();
4095 if (_service == proc->getName()) return false; // proc is not an elementary node
4096 Node* node = proc->getChildByName(_service);
4097 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4099 if (proc->componentInstanceMap.count(_instanceName))
4101 DEBTRACE(_instanceName);
4102 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4103 service->setComponent(compo);
4105 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4106 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4107 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4109 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4110 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4111 snode->addSubjectReference(subCompo);
4112 if (ssnode->_subRefComponent)
4114 SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4116 _oldInstance = oldcomp->getName();
4117 _oldcont = oldcomp->getComponent()->getContainer()->getName();
4118 subCompo->moveService(ssnode->_subRefComponent);
4121 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4126 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4129 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4132 catch (Exception& ex)
4134 DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4140 bool CommandAssociateServiceToComponent::localReverse()
4142 DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4145 Proc* proc = GuiContext::getCurrent()->getProc();
4146 if (_service == proc->getName()) return false; // proc is not an elementary node
4147 Node* node = proc->getChildByName(_service);
4148 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4150 ComponentInstance *compo;
4151 if (!proc->componentInstanceMap.count(_oldInstance))
4153 //component instance does not exist anymore recreate it
4154 ComponentInstance *oldcompo = service->getComponent();
4155 compo = oldcompo->cloneAlways();
4156 compo->setName(_oldInstance);
4157 proc->addComponentInstance(compo, _oldInstance);
4158 Container *cont = proc->containerMap[_oldcont];
4159 compo->setContainer(cont);
4160 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
4161 sproc->addSubjectComponent(compo);
4165 compo = proc->componentInstanceMap[_oldInstance];
4168 DEBTRACE(_oldInstance);
4169 service->setComponent(compo);
4171 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4172 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4173 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4175 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4176 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4177 snode->addSubjectReference(subCompo);
4178 if (ssnode->_subRefComponent)
4179 subCompo->moveService(ssnode->_subRefComponent);
4181 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4186 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4189 catch (Exception& ex)
4191 DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4197 // ----------------------------------------------------------------------------
4199 CommandAddComponentFromCatalog::CommandAddComponentFromCatalog(YACS::ENGINE::Catalog* catalog,
4200 std::string position,
4202 std::string service)
4203 : Command(), _catalog(catalog), _position(position), _compo(compo), _service(service)
4205 DEBTRACE("CommandAddComponentFromCatalog::CommandAddComponentFromCatalog " << position << " " << compo << " " << service);
4207 _createdInstance = false;
4210 std::string CommandAddComponentFromCatalog::dump()
4212 string ret = "CommandAddComponentFromCatalog " + _position + " " + _compo + " " + _service;
4216 bool CommandAddComponentFromCatalog::localExecute()
4218 DEBTRACE("CommandAddComponentFromCatalog::localExecute");
4221 DEBTRACE("_nameInProc: " << _nameInProc);
4222 Proc* proc = GuiContext::getCurrent()->getProc();
4224 if (!_position.empty()) node = proc->getChildByName(_position);
4225 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4226 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4227 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4229 if (_catalog->_componentMap.count(_compo))
4231 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compo];
4232 if (compodef->_serviceMap.count(_service))
4234 Proc* proc = GuiContext::getCurrent()->getProc();
4235 ComponentInstance *instance =ssnode->_serviceNode->getComponent();
4237 SubjectComponent* subCompo = 0;
4238 _createdInstance = false;
4239 if(!GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
4241 _createdInstance = true;
4242 //automatic rename of the component instance by the proc on first execute
4243 DEBTRACE("name given to proc:" << _nameInProc);
4244 proc->addComponentInstance(instance,_nameInProc, true);
4245 _nameInProc= instance->getInstanceName();
4246 DEBTRACE("name given by proc:" << _nameInProc);
4247 subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
4250 subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
4252 ssnode->addSubjectReference(subCompo);
4253 YASSERT(! ssnode->_subRefComponent);
4254 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4259 catch (Exception& ex)
4261 DEBTRACE("CommandAddComponentFromCatalog::localExecute() : " << ex.what());
4267 bool CommandAddComponentFromCatalog::localReverse()
4269 DEBTRACE("CommandAddComponentFromCatalog::localReverse");
4272 Proc* proc = GuiContext::getCurrent()->getProc();
4274 if (!_position.empty()) node = proc->getChildByName(_position);
4275 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4276 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4277 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4280 DEBTRACE("_nameInProc: " << _nameInProc);
4281 YASSERT(proc->componentInstanceMap.count(_nameInProc));
4282 ComponentInstance *compo = proc->componentInstanceMap[_nameInProc];
4283 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4284 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4286 subCompo->detachService(ssnode);
4287 if (subCompo->hasServices())
4288 throw YACS::Exception("Component instance with services attached, not removed");
4289 Container *cont = compo->getContainer();
4290 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4291 SubjectContainerBase *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4292 subcont->detachComponent(subCompo);
4293 //remove componentInstance from proc, from context
4294 if (_createdInstance)
4296 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
4297 proc->removeComponentInstance(compo);
4299 DEBTRACE("_nameInProc: " << _nameInProc);
4302 catch (Exception& ex)
4304 DEBTRACE("CommandAddComponentFromCatalog::localReverse() : " << ex.what());