1 // Copyright (C) 2006-2012 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.
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 "SalomeComponent.hxx"
53 #include "TypeCode.hxx"
54 #include "RuntimeSALOME.hxx"
55 #include "TypeConversions.hxx"
57 #include "guiContext.hxx"
64 #include "YacsTrace.hxx"
69 using namespace YACS::ENGINE;
70 using namespace YACS::HMI;
73 static std::map<int, std::string> createErrorMsgMap()
75 std::map<int, std::string> m;
76 m[1] = "\nUse the [Ctrl] Drag_N_Drop method if you want to create a input/output link without the associated control link";
80 std::map<int, std::string> ErrorMsg = createErrorMsgMap();
82 void setErrorMsg(YACS::Exception& ex)
84 DEBTRACE("errorNumber= "<<ex.errNumber);
85 if(ex.errNumber > 0 && ErrorMsg.count(ex.errNumber) != 0)
87 DEBTRACE(ErrorMsg[ex.errNumber]);
88 GuiContext::getCurrent()->_lastErrorMessage = ex.what() + ErrorMsg[ex.errNumber];
91 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
94 std::map<int, std::string> ProcInvoc::_typeNameMap;
96 // ----------------------------------------------------------------------------
98 ProcInvoc::ProcInvoc()
101 _typeNameMap.clear();
102 _typeNameMap[SALOMEPROC] = "SALOMEPROC";
103 _typeNameMap[BLOC] = "BLOC";
104 _typeNameMap[FOREACHLOOP] = "FOREACHLOOP";
105 _typeNameMap[OPTIMIZERLOOP] = "OPTIMIZERLOOP";
106 _typeNameMap[FORLOOP] = "FORLOOP";
107 _typeNameMap[WHILELOOP] = "WHILELOOP";
108 _typeNameMap[SWITCH] = "SWITCH";
109 _typeNameMap[PYTHONNODE] = "PYTHONNODE";
110 _typeNameMap[PYFUNCNODE] = "PYFUNCNODE";
111 _typeNameMap[CORBANODE] = "CORBANODE";
112 _typeNameMap[SALOMENODE] = "SALOMENODE";
113 _typeNameMap[CPPNODE] = "CPPNODE";
114 _typeNameMap[SALOMEPYTHONNODE] = "SALOMEPYTHONNODE";
115 _typeNameMap[XMLNODE] = "XMLNODE";
116 _typeNameMap[SPLITTERNODE] = "SPLITTERNODE";
117 _typeNameMap[DFTODSFORLOOPNODE] = "DFTODSFORLOOPNODE";
118 _typeNameMap[DSTODFFORLOOPNODE] = "DSTODFFORLOOPNODE";
119 _typeNameMap[PRESETNODE] = "PRESETNODE";
120 _typeNameMap[OUTNODE] = "OUTNODE";
121 _typeNameMap[STUDYINNODE] = "STUDYINNODE";
122 _typeNameMap[STUDYOUTNODE] = "STUDYOUTNODE";
123 _typeNameMap[INPUTPORT] = "INPUTPORT";
124 _typeNameMap[OUTPUTPORT] = "OUTPUTPORT";
125 _typeNameMap[INPUTDATASTREAMPORT] = "INPUTDATASTREAMPORT";
126 _typeNameMap[OUTPUTDATASTREAMPORT] = "OUTPUTDATASTREAMPORT";
127 _typeNameMap[DATALINK] = "DATALINK";
128 _typeNameMap[CONTROLLINK] = "CONTROLLINK";
129 _typeNameMap[CONTAINER] = "CONTAINER";
130 _typeNameMap[COMPONENT] = "COMPONENT";
131 _typeNameMap[REFERENCE] = "REFERENCE";
132 _typeNameMap[DATATYPE] = "DATATYPE";
135 TypeOfElem ProcInvoc::getTypeOfNode(YACS::ENGINE::Node* node)
137 TypeOfElem nodeType = UNKNOWN;
138 if (dynamic_cast<YACS::ENGINE::Bloc*>(node)) nodeType = BLOC;
139 else if (dynamic_cast<YACS::ENGINE::PythonNode*>(node)) nodeType = PYTHONNODE;
140 else if (dynamic_cast<YACS::ENGINE::PyFuncNode*>(node)) nodeType = PYFUNCNODE;
141 else if (dynamic_cast<YACS::ENGINE::CORBANode*>(node)) nodeType = CORBANODE;
142 else if (dynamic_cast<YACS::ENGINE::CppNode*>(node)) nodeType = CPPNODE;
143 else if (dynamic_cast<YACS::ENGINE::SalomeNode*>(node)) nodeType = SALOMENODE;
144 else if (dynamic_cast<YACS::ENGINE::SalomePythonNode*>(node)) nodeType = SALOMEPYTHONNODE;
145 else if (dynamic_cast<YACS::ENGINE::XmlNode*>(node)) nodeType = XMLNODE;
146 else if (dynamic_cast<YACS::ENGINE::SplitterNode*>(node)) nodeType = SPLITTERNODE;
147 else if (dynamic_cast<YACS::ENGINE::ForLoop*>(node)) nodeType = FORLOOP;
148 else if (dynamic_cast<YACS::ENGINE::WhileLoop*>(node)) nodeType = WHILELOOP;
149 else if (dynamic_cast<YACS::ENGINE::Switch*>(node)) nodeType = SWITCH;
150 else if (dynamic_cast<YACS::ENGINE::ForEachLoop*>(node)) nodeType = FOREACHLOOP;
151 else if (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(node)) nodeType = OPTIMIZERLOOP;
152 else if (dynamic_cast<YACS::ENGINE::PresetNode*>(node)) nodeType = PRESETNODE;
153 else if (dynamic_cast<YACS::ENGINE::OutNode*>(node)) nodeType = OUTNODE;
154 else if (dynamic_cast<YACS::ENGINE::StudyInNode*>(node)) nodeType = STUDYINNODE;
155 else if (dynamic_cast<YACS::ENGINE::StudyOutNode*>(node)) nodeType = STUDYOUTNODE;
159 TypeOfElem ProcInvoc::getTypeOfPort(YACS::ENGINE::DataPort* port)
161 TypeOfElem portType = UNKNOWN;
162 if (dynamic_cast<YACS::ENGINE::InputPort*>(port)) portType = INPUTPORT;
163 else if (dynamic_cast<YACS::ENGINE::OutputPort*>(port)) portType = OUTPUTPORT;
164 else if (dynamic_cast<YACS::ENGINE::InputDataStreamPort*>(port)) portType = INPUTDATASTREAMPORT;
165 else if (dynamic_cast<YACS::ENGINE::OutputDataStreamPort*>(port)) portType = OUTPUTDATASTREAMPORT;
169 std::string ProcInvoc::getTypeName(TypeOfElem type)
171 if (_typeNameMap.count(type))
172 return _typeNameMap[type];
177 // ----------------------------------------------------------------------------
179 CommandAddNodeFromCatalog::CommandAddNodeFromCatalog(YACS::ENGINE::Catalog *catalog,
182 std::string position,
186 : Command(), _catalog(catalog), _compoName(compo), _typeName(type),
187 _position(position), _name(name), _newCompoInst(newCompoInst), _swCase(swCase)
189 DEBTRACE("CommandAddNodeFromCatalog " << compo << " " << type << " " << position << " " << name);
194 std::string CommandAddNodeFromCatalog::dump()
196 string ret ="CommandAddNodeFromCatalog " + _compoName + " " + _typeName + " " + _position + " " + _name;
200 YACS::ENGINE::Node *CommandAddNodeFromCatalog::getNode()
205 YACS::HMI::SubjectNode *CommandAddNodeFromCatalog::getSubjectNode()
210 bool CommandAddNodeFromCatalog::localExecute()
212 DEBTRACE("CommandAddNodeFromCatalog::localExecute");
215 Node *nodeToClone = 0;
218 if (_compoName.empty())
220 if (_catalog->_nodeMap.count(_typeName))
221 nodeToClone = _catalog->_nodeMap[_typeName];
222 else if (_catalog->_composednodeMap.count(_typeName))
223 nodeToClone = _catalog->_composednodeMap[_typeName];
226 if (_catalog->_componentMap.count(_compoName))
228 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compoName];
229 if (compodef->_serviceMap.count(_typeName))
230 nodeToClone = compodef->_serviceMap[_typeName];
233 _typeNode = ProcInvoc::getTypeOfNode(nodeToClone);
235 GuiContext::getCurrent()->setCurrentCatalog(_catalog);
236 Proc* proc = GuiContext::getCurrent()->getProc();
238 ServiceNode *service = 0;
240 if (!_position.empty()) node = proc->getChildByName(_position);
241 ComposedNode* father =dynamic_cast<ComposedNode*> (node);
242 if (father && nodeToClone)
244 son = nodeToClone->clone(0);
246 service = dynamic_cast<ServiceNode*>(son);
249 // Node creation eventually reusing old component instance
250 ComponentInstance *compo = 0;
252 compo = service->getComponent();
256 std::string compoName=compo->getCompoName();
258 std::string compoInstName=compo->getInstanceName();
259 DEBTRACE(compoInstName);
262 ComponentInstance *lastcompo = GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName];
266 DEBTRACE(lastcompo->getInstanceName());
267 service->setComponent(lastcompo); // use the last component instance of the same type and not a new instance
270 GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
273 GuiContext::getCurrent()->_mapOfLastComponentInstance[compoName]=compo;
278 TypeOfElem fatherType = ProcInvoc::getTypeOfNode(father);
282 (dynamic_cast<YACS::ENGINE::Bloc*>(father))->edAddChild(son);
285 (dynamic_cast<YACS::ENGINE::ForLoop*>(father))->edSetNode(son);
288 (dynamic_cast<YACS::ENGINE::WhileLoop*>(father))->edSetNode(son);
291 (dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
294 (dynamic_cast<YACS::ENGINE::ForEachLoop*>(father))->edSetNode(son);
297 (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
305 throw YACS::Exception("node from catalog is not correct: check if catalog is up to date!");
307 SubjectComposedNode *sfather = dynamic_cast<SubjectComposedNode*>(GuiContext::getCurrent()->_mapOfSubjectNode[father]);
308 _snode= sfather->addSubjectNode(_node, "", _catalog, _compoName, _typeName);
309 _snode->loadChildren();
312 catch (Exception& ex)
314 DEBTRACE("CommandAddNode::localExecute() : " << ex.what());
322 bool CommandAddNodeFromCatalog::localReverse()
324 DEBTRACE("CommandAddNodeFromCatalog::localReverse");
327 Proc* proc = GuiContext::getCurrent()->getProc();
329 if (_position.empty())
332 nodeName = _position + "." + _name;
334 _node = proc->getChildByName(nodeName);
336 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_node));
337 _snode = GuiContext::getCurrent()->_mapOfSubjectNode[_node];
339 Subject *father=_snode->getParent();
341 DEBTRACE(father->getName());
342 Subject::erase(_snode);
348 father->select(true);
349 father->update(REMOVE,0,0);
353 catch (Exception& ex)
355 DEBTRACE("CommandAddNodeFromCatalog::localReverse(): " << ex.what());
361 // ----------------------------------------------------------------------------
363 CommandReparentNode::CommandReparentNode(std::string position,
364 std::string newParent)
365 : Command(), _position(position), _newParent(newParent)
367 DEBTRACE("CommandReparentNode::CommandReparentNode " << _position << " " << _newParent);
371 std::string CommandReparentNode::dump()
373 string ret ="CommandReparentNode " + _position + " " + _newParent;
377 bool CommandReparentNode::localExecute()
379 DEBTRACE("CommandReparentNode::localExecute");
380 Proc* proc = GuiContext::getCurrent()->getProc();
384 if (_position == proc->getName())
385 throw YACS::Exception("Reparent the proc (main bloc) is impossible");
386 node = proc->getChildByName(_position);
387 ComposedNode *oldFather = node->getFather();
388 ComposedNode *newFather = proc;
390 if (_newParent != proc->getName())
392 newF = proc->getChildByName(_newParent);
393 newFather = dynamic_cast<ComposedNode*>(newF);
396 throw YACS::Exception("new parent must be a composed node");
397 if (oldFather == newFather)
398 throw YACS::Exception("no need to reparent to the same parent");
399 if (ComposedNode *cnode = dynamic_cast<ComposedNode*>(node))
400 if (cnode->isInMyDescendance(newFather))
401 throw YACS::Exception("reparent a node to one of it's children is impossible");
402 if (Loop *loop = dynamic_cast<Loop*>(newFather))
403 if (!loop->edGetDirectDescendants().empty())
404 throw YACS::Exception("Already a node in a new parent of Loop type");
405 if (DynParaLoop * dpl = dynamic_cast<DynParaLoop*>(newFather))
406 if (dpl->getExecNode() != NULL)
407 throw YACS::Exception("Already an execution node in the new parent of type dynamic loop");
408 Node *nodeSameName = 0;
411 nodeSameName = newFather->getChildByName(node->getName());
417 throw YACS::Exception("there is already a child of same name in the new parent");
418 SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
419 Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
420 Subject *subn = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
421 SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
422 SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
423 //save existing links
425 snode->removeExternalLinks();
426 snode->removeExternalControlLinks();
427 sop->houseKeepingAfterCutPaste(true, snode);
428 oldFather->edRemoveChild(node);
429 newFather->edAddChild(node);
430 snp->houseKeepingAfterCutPaste(false, snode);
432 snode->restoreLinks();
433 if (oldFather == proc) _oldParent = proc->getName();
434 else _oldParent = proc->getChildName(oldFather);
435 _newpos = proc->getChildName(node);
436 sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
437 snp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
438 snode->recursiveUpdate(RENAME, 0, snode);
439 snode->_parent = snp;
441 catch (Exception& ex)
443 DEBTRACE("CommandReparentNode::localExecute() : " << ex.what());
449 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
455 bool CommandReparentNode::localReverse()
457 DEBTRACE("CommandReparentNode::localReverse " << _newpos << " " << _oldParent);
458 Proc* proc = GuiContext::getCurrent()->getProc();
462 node = proc->getChildByName(_newpos);
463 ComposedNode *father = node->getFather();
464 ComposedNode *oldFather = proc;
466 if (_oldParent != proc->getName())
468 oldF = proc->getChildByName(_oldParent);
469 oldFather = dynamic_cast<ComposedNode*>(oldF);
471 SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
472 Subject *subn = GuiContext::getCurrent()->_mapOfSubjectNode[father];
473 Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
474 SubjectComposedNode* snp = dynamic_cast<SubjectComposedNode*>(subn);
475 SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
476 //save existing links
478 snode->removeExternalLinks();
479 snode->removeExternalControlLinks();
480 snp->houseKeepingAfterCutPaste(true, snode);
481 father->edRemoveChild(node);
482 oldFather->edAddChild(node);
483 sop->houseKeepingAfterCutPaste(false, snode);
485 snode->restoreLinks();
486 snp->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
487 sop->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
488 snode->recursiveUpdate(RENAME, 0, snode);
489 snode->_parent = sop;
491 catch (Exception& ex)
493 DEBTRACE("CommandReparentNode::localReverse() : " << ex.what());
499 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
505 // ----------------------------------------------------------------------------
506 CommandPutInComposedNode::CommandPutInComposedNode(std::string position,
507 std::string newParent,
509 bool toSaveRestoreLinks)
510 : Command(), _position(position), _newParent(newParent), _type(type), _toSaveRestoreLinks(toSaveRestoreLinks)
512 DEBTRACE("CommandPutInComposedNode::CommandPutInComposedNode " << _position << " " << _newParent);
516 std::string CommandPutInComposedNode::dump()
518 string save = _toSaveRestoreLinks ? "true" : "false";
519 string ret ="CommandPutInComposedNode " + _position + " " + _newParent + " " + _type + " " + save;
524 bool CommandPutInComposedNode::localExecute()
526 DEBTRACE("CommandPutInComposedNode::localExecute");
527 Proc* proc = GuiContext::getCurrent()->getProc();
531 if (_position == proc->getName())
532 throw YACS::Exception("You cannot put the proc (main bloc) in a " + _type);
533 node = proc->getChildByName(_position);
534 ComposedNode *oldFather = node->getFather();
535 SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
536 Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
537 SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
538 if (_toSaveRestoreLinks)
539 snode->saveLinks(); //save existing links
540 //remove external links
541 snode->removeExternalLinks();
542 snode->removeExternalControlLinks();
543 //remove subject node from subject old father
544 sop->houseKeepingAfterCutPaste(true, snode);
545 //remove node from old father
546 oldFather->edRemoveChild(node);
548 sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
550 // try to find a node with the given name:
551 // success: use it as target composed node
552 // fail: create such a node and use it
553 std::list<Node*> children = proc->getChildren();
554 Node* composednode = 0;
555 SubjectNode *scomposednode = 0;
556 for (list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
558 if ( _newParent == (*it)->getName() )
560 //get an existing ComposedNode with name _newParent
561 composednode = (*it);
565 // target node was found
568 scomposednode = GuiContext::getCurrent()->_mapOfSubjectNode[composednode];
570 // creation of target node
573 //create a ComposedNode (type _type) with name _newParent
574 YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog();
575 Node* nodeToClone = catalog->_composednodeMap[_type];
576 composednode = nodeToClone->clone(0);
577 composednode->setName(_newParent);
578 //add the new composednode as child of oldfather
579 oldFather->edAddChild(composednode);
580 //create the subject composednode
581 scomposednode = sop->addSubjectNode(composednode,"",catalog,"",_type);
584 //add the old node as child of new composednode
585 (dynamic_cast<YACS::ENGINE::ComposedNode*>(composednode))->edAddChild(node);
586 _newpos = proc->getChildName(node);
587 //add the subject node to subject composednode
588 (dynamic_cast<SubjectComposedNode*>(scomposednode))->houseKeepingAfterCutPaste(false, snode);
589 snode->setParent(scomposednode);
590 if (_toSaveRestoreLinks)
591 snode->restoreLinks(); //restore links
593 scomposednode->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
594 snode->recursiveUpdate(RENAME, 0, snode);
597 catch (Exception& ex)
599 DEBTRACE("CommandPutInComposedNode::localExecute() : " << ex.what());
605 GuiContext::getCurrent()->_lastErrorMessage = "Unknown exception";
611 bool CommandPutInComposedNode::localReverse()
613 DEBTRACE("CommandPutInComposedNode::localReverse");
614 Proc* proc = GuiContext::getCurrent()->getProc();
618 YASSERT(_newpos != proc->getName())
619 node = proc->getChildByName(_newpos);
620 ComposedNode *oldFather = node->getFather();
621 SubjectNode * snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
622 Subject *subo = GuiContext::getCurrent()->_mapOfSubjectNode[oldFather];
623 SubjectComposedNode* sop = dynamic_cast<SubjectComposedNode*>(subo);
624 //save existing links
626 //remove external links
627 snode->removeExternalLinks();
628 snode->removeExternalControlLinks();
629 //remove subject node from subject old father
630 sop->houseKeepingAfterCutPaste(true, snode);
631 //remove node from old father
632 oldFather->edRemoveChild(node);
633 //refresh node views, temporary paste in proc to keep widgets associated to node
634 sop->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
635 GuiContext::getCurrent()->getSubjectProc()->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
637 //remove composed node oldFather
638 ComposedNode *oldGrandFather = oldFather->getFather();
639 Subject *subog = GuiContext::getCurrent()->_mapOfSubjectNode[oldGrandFather];
640 SubjectComposedNode* sogp = dynamic_cast<SubjectComposedNode*>(subog);
643 //add the old node as child of new composednode
644 oldGrandFather->edAddChild(node);
645 _newpos = proc->getChildName(node);
646 //add the subject node to subject composednode
647 sogp->houseKeepingAfterCutPaste(false, snode);
648 snode->setParent(sogp);
650 snode->restoreLinks();
652 GuiContext::getCurrent()->getSubjectProc()->update(CUT, ProcInvoc::getTypeOfNode(node), snode);
653 sogp->update(PASTE, ProcInvoc::getTypeOfNode(node), snode);
654 snode->recursiveUpdate(RENAME, 0, snode);
657 catch (Exception& ex)
659 DEBTRACE("CommandPutInComposedNode::localReverse() : " << ex.what());
665 // ----------------------------------------------------------------------------
667 CommandCopyNode::CommandCopyNode(YACS::ENGINE::Proc *fromproc,
668 std::string position,
669 std::string newParent,
671 : Command(), _fromproc(fromproc), _position(position), _newParent(newParent), _newName(""), _clone(0), _case(swCase)
673 DEBTRACE("CommandCopyNode::CommandCopyNode " << _position << " " << _newParent);
676 std::string CommandCopyNode::dump()
678 string ret ="CommandCopyNode " + _position + " " + _newParent;
682 YACS::ENGINE::Node *CommandCopyNode::getNode()
687 bool CommandCopyNode::localExecute()
689 DEBTRACE("CommandCopyNode::localExecute");
690 Proc* proc = GuiContext::getCurrent()->getProc();
694 if (_position == _fromproc->getName())
695 throw YACS::Exception("Copy the proc (main bloc) is impossible");
696 node = _fromproc->getChildByName(_position);
697 ComposedNode *oldFather = node->getFather();
698 ComposedNode *newFather = proc;
700 if (_newParent != proc->getName())
702 newF = proc->getChildByName(_newParent);
703 newFather = dynamic_cast<ComposedNode*>(newF);
706 throw YACS::Exception("new parent must be a composed node");
707 if (Loop *loop = dynamic_cast<Loop*>(newFather))
708 if (!loop->edGetDirectDescendants().empty())
709 throw YACS::Exception("Already a node in a new parent of Loop type");
710 //_clone = node->clone(newFather);
711 _clone = node->clone(0);
713 throw YACS::Exception("Node cannot be cloned");
715 bool sameName = true;
720 s << node->getName();
721 if (nodeSuffix >= 0) // --- first try <0 means without suffix
726 Node *nodeSameName = newFather->getChildByName(s.str());
735 _clone->setName(s.str());
736 _newName = _clone->getName();
738 if (YACS::ENGINE::Switch* theswitch = dynamic_cast<YACS::ENGINE::Switch*>(newFather))
740 DEBTRACE("father is a switch " << newFather->getName());
742 if(theswitch->edGetNode(_case))
744 //the case is already used. Try another one
745 theCase=theswitch->getMaxCase()+1;
747 theswitch->edSetNode(theCase,_clone);
750 newFather->edAddChild(_clone);
752 _newName = _clone->getQualifiedName();
755 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[newFather];
756 SubjectComposedNode *snp = dynamic_cast<SubjectComposedNode*>(sub);
757 SubjectNode *son = snp->addSubjectNode(_clone);
761 catch (Exception& ex)
763 DEBTRACE("CommandCopyNode::localExecute() : " << ex.what());
767 return (_clone != 0);
770 bool CommandCopyNode::localReverse()
772 DEBTRACE("CommandCopyNode::localReverse " << _position << " " << _newParent);
775 Proc* proc = GuiContext::getCurrent()->getProc();
776 string nodeName = _newParent + "." + _newName;
777 if (_newParent == proc->getName())
780 _clone = proc->getChildByName(nodeName);
782 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(_clone));
783 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[_clone];
784 Subject *father = snode->getParent();
785 Subject::erase(snode);
790 father->select(true);
791 father->update(REMOVE,0,0);
795 catch (Exception& ex)
797 DEBTRACE("CommandCopyNode::localReverse(): " << ex.what());
804 // ----------------------------------------------------------------------------
806 CommandRenameNode::CommandRenameNode(std::string position, std::string name)
807 : Command(), _position(position), _name(name)
809 DEBTRACE("CommandRenameNode::CommandRenameNode " << _position << " " << _name);
814 std::string CommandRenameNode::dump()
816 string ret ="CommandRenameNode " + _position + " " + _name;
820 bool CommandRenameNode::localExecute()
822 DEBTRACE("CommandRenameNode::localExecute");
823 Proc* proc = GuiContext::getCurrent()->getProc();
827 if (_position != proc->getName()) node = proc->getChildByName(_position);
828 _oldName = node->getName();
829 node->setName(_name);
833 _newpos = proc->getChildName(node);
834 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
836 snode->recursiveUpdate(RENAME, 0, snode);
838 catch (Exception& ex)
840 DEBTRACE("CommandRenameNode::localExecute() : " << ex.what());
847 bool CommandRenameNode::localReverse()
849 DEBTRACE("CommandRenameNode::localReverse");
850 Proc* proc = GuiContext::getCurrent()->getProc();
854 if (_newpos != proc->getName()) node = proc->getChildByName(_newpos);
855 YASSERT(node->getName() == _name);
856 node->setName(_oldName);
857 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
859 snode->recursiveUpdate(RENAME, 0, snode);
861 catch (Exception& ex)
863 DEBTRACE("CommandRenameNode::localReverse() : " << ex.what());
870 // ----------------------------------------------------------------------------
872 CommandRenameContainer::CommandRenameContainer(std::string oldName, std::string newName)
873 : Command(), _oldName(oldName), _newName(newName)
875 DEBTRACE("CommandRenameContainer::CommandRenameContainer " << _oldName << " " << _newName);
878 std::string CommandRenameContainer::dump()
880 string ret ="CommandRenameContainer " +_oldName + " " + _newName;
884 bool CommandRenameContainer::localExecute()
886 DEBTRACE("CommandRenameContainer::localExecute");
887 Proc* proc = GuiContext::getCurrent()->getProc();
888 Container *container = 0;
891 YASSERT(proc->containerMap.count(_oldName));
892 container = proc->containerMap[_oldName];
893 if (proc->containerMap.count(_newName))
895 GuiContext::getCurrent()->_lastErrorMessage = "Container name already existing";
898 proc->containerMap.erase(_oldName);
899 container->setName(_newName);
900 proc->containerMap[_newName] = container;
901 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
902 SubjectContainer *scont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
903 scont-> update(RENAME, 0, scont);
904 scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
906 catch (Exception& ex)
908 DEBTRACE("CommandRenameContainer::localExecute() : " << ex.what());
912 return (container != 0);
915 bool CommandRenameContainer::localReverse()
917 DEBTRACE("CommandRenameContainer::localReverse");
918 Proc* proc = GuiContext::getCurrent()->getProc();
919 Container *container = 0;
922 YASSERT(proc->containerMap.count(_newName));
923 container = proc->containerMap[_newName];
924 proc->containerMap.erase(_newName);
925 container->setName(_oldName);
926 proc->containerMap[_oldName] = container;
927 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
928 SubjectContainer *scont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
929 scont-> update(RENAME, 0, scont);
930 scont->notifyComponentsChange(ASSOCIATE, CONTAINER, scont);
932 catch (Exception& ex)
934 DEBTRACE("CommandRenameContainer::localReverse() : " << ex.what());
938 return (container != 0);
941 // ----------------------------------------------------------------------------
943 CommandRenameInDataPort::CommandRenameInDataPort(std::string position,
945 std::string newName, TypeOfElem portType)
946 : Command(), _position(position), _oldName(oldName), _newName(newName), _portType(portType)
948 DEBTRACE("CommandRenameInDataPort::CommandRenameInDataPort "
949 << _position << " " << _oldName<< " " << _newName);
952 std::string CommandRenameInDataPort::dump()
954 string ret ="CommandRenameInDataPort " + _position + " " + _oldName + " " + _newName;
958 bool CommandRenameInDataPort::localExecute()
960 DEBTRACE("CommandRenameInDataPort::localExecute");
961 Proc* proc = GuiContext::getCurrent()->getProc();
965 if (_position != proc->getName()) node = proc->getChildByName(_position);
970 if(_portType==INPUTPORT)
971 port = node->getInputPort(_newName);
973 port = node->getInputDataStreamPort(_newName);
975 catch (Exception& e) {} // --- raised when no existing port with _newName
977 throw Exception("there is already a port with the new name");
979 if(_portType==INPUTPORT)
980 port = node->getInputPort(_oldName);
982 port = node->getInputDataStreamPort(_oldName);
983 port->setName(_newName);
984 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
985 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
986 sport->update(RENAME, 0, sport);
988 catch (Exception& ex)
990 DEBTRACE("CommandRenameInDataPort::localExecute() : " << ex.what());
997 bool CommandRenameInDataPort::localReverse()
999 DEBTRACE("CommandRenameInDataPort::localReverse");
1000 Proc* proc = GuiContext::getCurrent()->getProc();
1004 if (_position != proc->getName()) node = proc->getChildByName(_position);
1009 if(_portType==INPUTPORT)
1010 port = node->getInputPort(_oldName);
1012 port = node->getInputDataStreamPort(_oldName);
1014 catch (Exception& e) {} // --- raised when no existing port with _newName
1016 throw Exception("there is already a port with the old name");
1018 if(_portType==INPUTPORT)
1019 port = node->getInputPort(_newName);
1021 port = node->getInputDataStreamPort(_newName);
1022 port->setName(_oldName);
1023 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1024 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1025 sport->update(RENAME, 0, sport);
1027 catch (Exception& ex)
1029 DEBTRACE("CommandRenameInDataPort::localReverse() : " << ex.what());
1036 // ----------------------------------------------------------------------------
1038 CommandRenameOutDataPort::CommandRenameOutDataPort(std::string position,
1039 std::string oldName,
1040 std::string newName, TypeOfElem portType)
1041 : Command(), _position(position), _oldName(oldName), _newName(newName), _portType(portType)
1043 DEBTRACE("CommandRenameOutDataPort::CommandRenameOutDataPort "
1044 << _position << " " << _oldName<< " " << _newName);
1047 std::string CommandRenameOutDataPort::dump()
1049 string ret ="CommandRenameOutDataPort " + _position + " " + _oldName + " " + _newName;
1053 bool CommandRenameOutDataPort::localExecute()
1055 DEBTRACE("CommandRenameOutDataPort::localExecute");
1056 Proc* proc = GuiContext::getCurrent()->getProc();
1060 if (_position != proc->getName()) node = proc->getChildByName(_position);
1064 if(_portType==OUTPUTPORT)
1065 port = node->getOutputPort(_newName);
1067 port = node->getOutputDataStreamPort(_newName);
1069 catch (Exception& e) {} // --- raised when no existing port with _newName
1071 throw Exception("there is already a port with the new name");
1073 if(_portType==OUTPUTPORT)
1074 port = node->getOutputPort(_oldName);
1076 port = node->getOutputDataStreamPort(_oldName);
1077 port->setName(_newName);
1078 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1079 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1080 sport->update(RENAME, 0, sport);
1082 catch (Exception& ex)
1084 DEBTRACE("CommandRenameOutDataPort::localExecute() : " << ex.what());
1091 bool CommandRenameOutDataPort::localReverse()
1093 DEBTRACE("CommandRenameOutDataPort::localReverse");
1094 Proc* proc = GuiContext::getCurrent()->getProc();
1098 if (_position != proc->getName()) node = proc->getChildByName(_position);
1102 if(_portType==OUTPUTPORT)
1103 port = node->getOutputPort(_oldName);
1105 port = node->getOutputDataStreamPort(_oldName);
1107 catch (Exception& e) {} // --- raised when no existing port with _newName
1109 throw Exception("there is already a port with the old name");
1111 if(_portType==OUTPUTPORT)
1112 port = node->getOutputPort(_newName);
1114 port = node->getOutputDataStreamPort(_newName);
1115 port->setName(_oldName);
1116 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(port));
1117 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[port];
1118 sport->update(RENAME, 0, sport);
1120 catch (Exception& ex)
1122 DEBTRACE("CommandRenameOutDataPort::localReverse() : " << ex.what());
1129 // ----------------------------------------------------------------------------
1131 CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog(YACS::ENGINE::Catalog* catalog,
1132 std::string typeName)
1133 : Command(), _catalog(catalog), _typeName(typeName)
1135 DEBTRACE("CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog: " << typeName);
1138 std::string CommandAddDataTypeFromCatalog::dump()
1140 string ret ="CommandAddDataTypeFromCatalog " + _typeName;
1144 YACS::ENGINE::TypeCode *CommandAddDataTypeFromCatalog::getTypeCode()
1147 if (GuiContext::getCurrent()->getProc()->typeMap.count(_typeName))
1148 return GuiContext::getCurrent()->getProc()->typeMap[_typeName];
1152 bool CommandAddDataTypeFromCatalog::localExecute()
1154 DEBTRACE("CommandAddDataTypeFromCatalog::localExecute");
1155 Proc* proc = GuiContext::getCurrent()->getProc();
1156 if (proc->typeMap.count(_typeName))
1158 DEBTRACE("typecode already existing in proc: " << _typeName);
1159 GuiContext::getCurrent()->_lastErrorMessage = "typeCode already existing in proc: " + _typeName;
1163 if (_catalog->_typeMap.count(_typeName))
1165 DEBTRACE("typecode found in catalog, cloned: " << _typeName);
1166 proc->typeMap[_typeName] = _catalog->_typeMap[_typeName]->clone();
1167 proc->typeMap[_typeName]->incrRef();
1168 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
1169 SubjectDataType *son = sproc->addSubjectDataType(getTypeCode(), _typeName);
1172 GuiContext::getCurrent()->_lastErrorMessage = "typecode not found in catalog: " + _typeName;
1176 bool CommandAddDataTypeFromCatalog::localReverse()
1178 DEBTRACE("CommandAddDataTypeFromCatalog::localReverse");
1181 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
1182 sproc->removeSubjectDataType(_typeName);
1185 catch (Exception& ex)
1187 DEBTRACE("CommandAddDataTypeFromCatalog::localReverse(): " << ex.what());
1194 // ----------------------------------------------------------------------------
1196 CommandAddInputPortFromCatalog::CommandAddInputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1200 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1206 std::string CommandAddInputPortFromCatalog::dump()
1208 string ret ="CommandAddInputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1212 YACS::ENGINE::InputPort *CommandAddInputPortFromCatalog::getInputPort()
1217 SubjectInputPort* CommandAddInputPortFromCatalog::getSubjectInputPort()
1222 bool CommandAddInputPortFromCatalog::localExecute()
1224 DEBTRACE("CommandAddInputPortFromCatalog::localExecute");
1228 Proc* proc = GuiContext::getCurrent()->getProc();
1229 Node* node = proc->getChildByName(_node);
1230 ElementaryNode* father = dynamic_cast<ElementaryNode*>(node);
1233 //try proc types and then catalog if not in proc
1234 if(proc->typeMap.count(_typePort))
1235 son = father->edAddInputPort(_name, proc->typeMap[_typePort]);
1236 else if (_catalog->_typeMap.count(_typePort))
1237 son = father->edAddInputPort(_name, _catalog->_typeMap[_typePort]);
1240 DEBTRACE(_typePort << " not found in catalog " << _catalog);
1241 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1245 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1246 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1247 _sip = snode->addSubjectInputPort(son, _name);
1248 snode->update(SYNCHRO,0,0); // when output port tab in node edition is visible
1250 catch (Exception& ex)
1252 DEBTRACE("CommandAddInputPortFromCatalog::localExecute() : " << ex.what());
1254 if (son) delete son;
1257 return (_inputPort != 0);
1260 bool CommandAddInputPortFromCatalog::localReverse()
1262 DEBTRACE("CommandAddInputPortFromCatalog::localReverse");
1265 Proc* proc = GuiContext::getCurrent()->getProc();
1266 Node *node = proc->getChildByName(_node);
1267 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1269 _inputPort = enode->getInputPort(_name);
1270 YASSERT(_inputPort);
1271 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_inputPort));
1272 _sip = dynamic_cast<SubjectInputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_inputPort]);
1275 Subject *father=_sip->getParent();
1276 Subject::erase(_sip);
1282 father->select(true);
1283 father->update(REMOVE,0,0);
1287 catch (Exception& ex)
1289 DEBTRACE("CommandAddInputPortFromCatalog::localReverse(): " << ex.what());
1295 // ----------------------------------------------------------------------------
1297 CommandAddOutputPortFromCatalog::CommandAddOutputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1301 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1307 std::string CommandAddOutputPortFromCatalog::dump()
1309 string ret ="CommandAddOutputPortFromCatalog " + _typePort + " " + _node + " " + _name;
1313 YACS::ENGINE::OutputPort *CommandAddOutputPortFromCatalog::getOutputPort()
1318 SubjectOutputPort* CommandAddOutputPortFromCatalog::getSubjectOutputPort()
1323 bool CommandAddOutputPortFromCatalog::localExecute()
1325 DEBTRACE("CommandAddOutputPortFromCatalog::localExecute");
1326 OutputPort *son = 0;
1329 Proc* proc = GuiContext::getCurrent()->getProc();
1330 Node* node = proc->getChildByName(_node);
1331 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1334 //try proc types and then catalog if not in proc
1335 if(proc->typeMap.count(_typePort))
1336 son = father->edAddOutputPort(_name, proc->typeMap[_typePort]);
1337 else if (_catalog->_typeMap.count(_typePort))
1338 son = father->edAddOutputPort(_name, _catalog->_typeMap[_typePort]);
1341 DEBTRACE(_typePort << " not found in catalog");
1342 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1346 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1347 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1348 _sop = snode->addSubjectOutputPort(son, _name);
1349 snode->update(SYNCHRO,0,0); // when input port tab in node edition is visible
1351 catch (Exception& ex)
1353 DEBTRACE("CommandAddOutputPortFromCatalog::localExecute() : " << ex.what());
1355 if (son) delete son;
1358 return (_outputPort != 0);
1361 bool CommandAddOutputPortFromCatalog::localReverse()
1363 DEBTRACE("CommandAddOutputPortFromCatalog::localReverse");
1366 Proc* proc = GuiContext::getCurrent()->getProc();
1367 Node *node = proc->getChildByName(_node);
1368 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1370 _outputPort = enode->getOutputPort(_name);
1371 YASSERT(_outputPort);
1372 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_outputPort));
1373 _sop = dynamic_cast<SubjectOutputPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_outputPort]);
1376 Subject *father=_sop->getParent();
1377 Subject::erase(_sop);
1383 father->select(true);
1384 father->update(REMOVE,0,0);
1388 catch (Exception& ex)
1390 DEBTRACE("CommandAddOutputPortFromCatalog::localReverse(): " << ex.what());
1396 // ----------------------------------------------------------------------------
1398 CommandAddIDSPortFromCatalog::CommandAddIDSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1402 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1408 std::string CommandAddIDSPortFromCatalog::dump()
1410 string ret ="CommandAddIDSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1414 YACS::ENGINE::InputDataStreamPort *CommandAddIDSPortFromCatalog::getIDSPort()
1416 DEBTRACE("CommandAddIDSPortFromCatalog");
1420 SubjectInputDataStreamPort* CommandAddIDSPortFromCatalog::getSubjectIDSPort()
1425 bool CommandAddIDSPortFromCatalog::localExecute()
1427 DEBTRACE("CommandAddIDSPortFromCatalog::localExecute");
1428 InputDataStreamPort *son = 0;
1431 Proc* proc = GuiContext::getCurrent()->getProc();
1432 Node* node = proc->getChildByName(_node);
1433 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1436 if (_catalog->_typeMap.count(_typePort))
1437 son = father->edAddInputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1440 DEBTRACE(_typePort << " not found in catalog");
1441 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1445 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1446 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1447 _sip = snode->addSubjectIDSPort(son, _name);
1449 catch (Exception& ex)
1451 DEBTRACE("CommandAddIDSPortFromCatalog::localExecute() : " << ex.what());
1453 if (son) delete son;
1456 return (_IDSPort != 0);
1459 bool CommandAddIDSPortFromCatalog::localReverse()
1461 DEBTRACE("CommandAddIDSPortFromCatalog::localReverse");
1464 Proc* proc = GuiContext::getCurrent()->getProc();
1465 Node *node = proc->getChildByName(_node);
1466 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1468 _IDSPort = enode->getInputDataStreamPort(_name);
1470 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_IDSPort));
1471 _sip = dynamic_cast<SubjectInputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_IDSPort]);
1474 Subject *father=_sip->getParent();
1475 Subject::erase(_sip);
1481 father->select(true);
1482 father->update(REMOVE,0,0);
1486 catch (Exception& ex)
1488 DEBTRACE("CommandAddIDSPortFromCatalog::localReverse(): " << ex.what());
1494 // ----------------------------------------------------------------------------
1496 CommandAddODSPortFromCatalog::CommandAddODSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
1500 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
1502 DEBTRACE("CommandAddODSPortFromCatalog");
1507 std::string CommandAddODSPortFromCatalog::dump()
1509 string ret ="CommandAddODSPortFromCatalog " + _typePort + " " + _node + " " + _name;
1513 YACS::ENGINE::OutputDataStreamPort *CommandAddODSPortFromCatalog::getODSPort()
1518 SubjectOutputDataStreamPort* CommandAddODSPortFromCatalog::getSubjectODSPort()
1523 bool CommandAddODSPortFromCatalog::localExecute()
1525 DEBTRACE("CommandAddODSPortFromCatalog::localExecute");
1526 OutputDataStreamPort *son = 0;
1529 Proc* proc = GuiContext::getCurrent()->getProc();
1530 Node* node = proc->getChildByName(_node);
1531 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
1534 if (_catalog->_typeMap.count(_typePort))
1535 son = father->edAddOutputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
1538 DEBTRACE(_typePort << " not found in catalog");
1539 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
1543 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1544 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1545 _sop = snode->addSubjectODSPort(son, _name);
1547 catch (Exception& ex)
1549 DEBTRACE("CommandAddODSPortFromCatalog::localExecute() : " << ex.what());
1551 if (son) delete son;
1554 return (_ODSPort != 0);
1557 bool CommandAddODSPortFromCatalog::localReverse()
1559 DEBTRACE("CommandAddODSPortFromCatalog::localReverse");
1562 Proc* proc = GuiContext::getCurrent()->getProc();
1563 Node *node = proc->getChildByName(_node);
1564 ElementaryNode* enode = dynamic_cast<ElementaryNode*>(node);
1566 _ODSPort = enode->getOutputDataStreamPort(_name);
1568 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(_ODSPort));
1569 _sop = dynamic_cast<SubjectOutputDataStreamPort*>(GuiContext::getCurrent()->_mapOfSubjectDataPort[_ODSPort]);
1572 Subject *father=_sop->getParent();
1573 Subject::erase(_sop);
1579 father->select(true);
1580 father->update(REMOVE,0,0);
1584 catch (Exception& ex)
1586 DEBTRACE("CommandAddODSPortFromCatalog::localReverse(): " << ex.what());
1592 // ----------------------------------------------------------------------------
1594 /*! move up or down a port in the list of ports of a node.
1595 * if isUp = 0, move down one step, if isUp = n>0, move up n steps.
1597 CommandOrderInputPorts::CommandOrderInputPorts(std::string node,
1600 : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1602 DEBTRACE("CommandOrderInputPorts");
1605 std::string CommandOrderInputPorts::dump()
1609 string ret ="CommandOrderInputPorts " + _node + " " + _port + " " + s.str();
1613 bool CommandOrderInputPorts::localExecute()
1615 DEBTRACE("CommandOrderInputPorts::localExecute " << _node << " " << _port << " " << _isUp);
1616 ElementaryNode* father = 0;
1619 Proc* proc = GuiContext::getCurrent()->getProc();
1620 Node* node = proc->getChildByName(_node);
1621 father = dynamic_cast<ElementaryNode*> (node);
1622 if (!father) return false;
1623 InputPort *portToMove = father->getInputPort(_port);
1624 DEBTRACE(portToMove->getName());
1626 list<InputPort*> plist = father->getSetOfInputPort();
1627 list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1632 if(pos == plist.begin())
1633 pos=plist.end(); // --- cycle
1635 do { pos--; isUp--; } while (isUp);
1640 if (pos == plist.end())
1641 pos = plist.begin(); // --- cycle
1643 pos++; // --- insert before the 2nd next port
1646 InputPort *portBefore = 0;
1647 if (pos != plist.end())
1648 portBefore = (*pos);
1650 plist.remove(portToMove);
1653 DEBTRACE(portBefore->getName());
1654 pos = find(plist.begin(), plist.end(), portBefore);
1656 for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1658 plist.insert(pos, portToMove);
1662 _rank = plist.size();
1663 plist.push_back(portToMove);
1665 father->edOrderInputPorts(plist);
1666 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1667 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1668 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1669 snode->update(ORDER, true, sport);
1670 snode->update(SYNCHRO, true, sport); // --- synchronise edition and scene
1672 catch (Exception& ex)
1674 DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1678 return (father != 0);
1681 bool CommandOrderInputPorts::localReverse()
1683 DEBTRACE("CommandOrderInputPorts::localReverse " << _node << " " << _port << " " << _isUp);
1684 ElementaryNode* father = 0;
1687 int isUpRev = -_isUp;
1688 if (isUpRev == 0) isUpRev =1;
1689 Proc* proc = GuiContext::getCurrent()->getProc();
1690 Node* node = proc->getChildByName(_node);
1691 father = dynamic_cast<ElementaryNode*> (node);
1692 if (!father) return false;
1693 InputPort *portToMove = father->getInputPort(_port);
1694 DEBTRACE(portToMove->getName());
1696 list<InputPort*> plist = father->getSetOfInputPort();
1697 list<InputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1701 if(pos == plist.begin())
1702 pos=plist.end(); // --- cycle
1704 do { pos--; isUpRev--; } while (isUpRev);
1709 if (pos == plist.end())
1710 pos = plist.begin(); // --- cycle
1712 do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1715 InputPort *portBefore = 0;
1716 if (pos != plist.end())
1717 portBefore = (*pos);
1719 plist.remove(portToMove);
1722 DEBTRACE(portBefore->getName());
1723 pos = find(plist.begin(), plist.end(), portBefore);
1725 for (list<InputPort*>::iterator it = plist.begin(); it != pos; ++it)
1727 plist.insert(pos, portToMove);
1731 _rank = plist.size();
1732 plist.push_back(portToMove);
1734 father->edOrderInputPorts(plist);
1735 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1736 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1737 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1738 snode->update(ORDER, true, sport);
1739 snode->update(SYNCHRO, true, sport); // --- synchronise edition and scene
1741 catch (Exception& ex)
1743 DEBTRACE("CommandOrderInputPorts::localExecute() : " << ex.what());
1747 return (father != 0);
1750 // ----------------------------------------------------------------------------
1752 /*! move up or down a port in the list of ports of a node.
1753 * if isUp = 0, move down one step, if isUp = n>0, move up n steps.
1755 CommandOrderOutputPorts::CommandOrderOutputPorts(std::string node,
1758 : Command(), _node(node), _port(port), _isUp(isUp), _rank(-1)
1760 DEBTRACE("CommandOrderOutputPorts");
1763 std::string CommandOrderOutputPorts::dump()
1767 string ret ="CommandOrderOutputPorts " + _node + " " + _port + " " + s.str();
1771 bool CommandOrderOutputPorts::localExecute()
1773 DEBTRACE("CommandOrderOutputPorts::localExecute " << _node << " " << _port << " " << _isUp);
1774 ElementaryNode* father = 0;
1777 Proc* proc = GuiContext::getCurrent()->getProc();
1778 Node* node = proc->getChildByName(_node);
1779 father = dynamic_cast<ElementaryNode*> (node);
1780 if (!father) return false;
1781 OutputPort *portToMove = father->getOutputPort(_port);
1782 DEBTRACE(portToMove->getName());
1784 list<OutputPort*> plist = father->getSetOfOutputPort();
1785 list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1790 if(pos == plist.begin())
1791 pos=plist.end(); // --- cycle
1793 do { pos--; isUp--; } while (isUp);
1798 if (pos == plist.end())
1799 pos = plist.begin(); // --- cycle
1801 pos++; // --- insert before the 2nd next port
1804 OutputPort *portBefore = 0;
1805 if (pos != plist.end())
1806 portBefore = (*pos);
1808 plist.remove(portToMove);
1811 DEBTRACE(portBefore->getName());
1812 pos = find(plist.begin(), plist.end(), portBefore);
1814 for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1816 plist.insert(pos, portToMove);
1820 _rank = plist.size();
1821 plist.push_back(portToMove);
1823 father->edOrderOutputPorts(plist);
1824 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1825 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1826 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1827 snode->update(ORDER, false, sport);
1828 snode->update(SYNCHRO, false, sport); // --- synchronise edition and scene
1830 catch (Exception& ex)
1832 DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1836 return (father != 0);
1839 bool CommandOrderOutputPorts::localReverse()
1841 DEBTRACE("CommandOrderOutputPorts::localReverse " << _node << " " << _port << " " << _isUp);
1842 ElementaryNode* father = 0;
1845 int isUpRev = -_isUp;
1846 if (isUpRev == 0) isUpRev =1;
1847 Proc* proc = GuiContext::getCurrent()->getProc();
1848 Node* node = proc->getChildByName(_node);
1849 father = dynamic_cast<ElementaryNode*> (node);
1850 if (!father) return false;
1851 OutputPort *portToMove = father->getOutputPort(_port);
1852 DEBTRACE(portToMove->getName());
1854 list<OutputPort*> plist = father->getSetOfOutputPort();
1855 list<OutputPort*>::iterator pos = find(plist.begin(), plist.end(), portToMove);
1859 if(pos == plist.begin())
1860 pos=plist.end(); // --- cycle
1862 do { pos--; isUpRev--; } while (isUpRev);
1867 if (pos == plist.end())
1868 pos = plist.begin(); // --- cycle
1870 do { pos++; isUpRev++; } while (isUpRev<0);// --- insert before the 2nd next port
1873 OutputPort *portBefore = 0;
1874 if (pos != plist.end())
1875 portBefore = (*pos);
1877 plist.remove(portToMove);
1880 DEBTRACE(portBefore->getName());
1881 pos = find(plist.begin(), plist.end(), portBefore);
1883 for (list<OutputPort*>::iterator it = plist.begin(); it != pos; ++it)
1885 plist.insert(pos, portToMove);
1889 _rank = plist.size();
1890 plist.push_back(portToMove);
1892 father->edOrderOutputPorts(plist);
1893 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1894 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1895 SubjectDataPort *sport = GuiContext::getCurrent()->_mapOfSubjectDataPort[portToMove];
1896 snode->update(ORDER, false, sport);
1897 snode->update(SYNCHRO, false, sport); // --- synchronise edition and scene
1899 catch (Exception& ex)
1901 DEBTRACE("CommandOrderOutputPorts::localExecute() : " << ex.what());
1905 return (father != 0);
1908 // ----------------------------------------------------------------------------
1910 CommandDestroy::CommandDestroy(TypeOfElem elemType,
1911 std::string startnode, std::string startport, TypeOfElem startportType,
1912 std::string endnode, std::string endport, TypeOfElem endportType)
1913 : Command(), _elemType(elemType), _startnode(startnode), _startport(startport),
1914 _endnode(endnode), _endport(endport), _startportType(startportType), _endportType(endportType)
1916 DEBTRACE("CommandDestroy::CommandDestroy");
1917 _normalReverse = false;
1920 std::string CommandDestroy::dump()
1922 string ret ="CommandDestroy " + ProcInvoc::getTypeName(_elemType);
1923 ret += " " + _startnode + " " + _startport;
1924 ret += " " + _endnode + " " + _endport;
1928 bool CommandDestroy::localExecute()
1930 DEBTRACE("CommandDestroy::localExecute");
1933 Proc* proc = GuiContext::getCurrent()->getProc();
1934 Subject *subject = 0;
1935 Subject *father = 0;
1950 case SALOMEPYTHONNODE:
1953 case DFTODSFORLOOPNODE:
1954 case DSTODFFORLOOPNODE:
1961 if (!_startnode.empty()) node = proc->getChildByName(_startnode);
1962 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
1963 subject = GuiContext::getCurrent()->_mapOfSubjectNode[node];
1964 father = subject->getParent();
1969 Node* node = proc->getChildByName(_startnode);
1970 InPort* inp = node->getInputPort(_startport);
1971 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
1972 subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
1973 father = subject->getParent();
1976 case INPUTDATASTREAMPORT:
1978 Node* node = proc->getChildByName(_startnode);
1979 InPort* inp = node->getInputDataStreamPort(_startport);
1980 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
1981 subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
1982 father = subject->getParent();
1987 Node* node = proc->getChildByName(_startnode);
1988 OutPort* outp = node->getOutputPort(_startport);
1989 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
1990 subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
1991 father = subject->getParent();
1994 case OUTPUTDATASTREAMPORT:
1996 Node* node = proc->getChildByName(_startnode);
1997 OutPort* outp = node->getOutputDataStreamPort(_startport);
1998 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
1999 subject = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2000 father = subject->getParent();
2005 Node* outn = proc->getChildByName(_startnode);
2006 Node* inn = proc->getChildByName(_endnode);
2011 if(_startportType == OUTPUTPORT)
2012 outp = outn->getOutputPort(_startport);
2014 outp = outn->getOutputDataStreamPort(_startport);
2016 if(_endportType == INPUTPORT)
2017 inp = inn->getInputPort(_endport);
2019 inp = inn->getInputDataStreamPort(_endport);
2021 pair<OutPort*,InPort*> keymap = pair<OutPort*,InPort*>(outp,inp);
2022 YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(keymap));
2023 subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
2024 father = subject->getParent();
2029 Node* outn = proc->getChildByName(_startnode);
2030 Node* inn = proc->getChildByName(_endnode);
2031 pair<Node*,Node*> keymap = pair<Node*,Node*>(outn,inn);
2032 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keymap));
2033 subject = GuiContext::getCurrent()->_mapOfSubjectControlLink[keymap];
2034 father = subject->getParent();
2039 Container *container = proc->containerMap[_startnode];
2040 subject = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
2047 throw Exception("Command Destroy not implemented for that type");
2051 Subject::erase(subject);
2054 father->select(true);
2055 father->update(REMOVE, 0, 0);
2060 catch (Exception& ex)
2062 DEBTRACE("CommandDestroy::localExecute() : " << ex.what());
2068 bool CommandDestroy::localReverse()
2070 DEBTRACE("CommandDestroy::localReverse");
2071 //! nothing to do here, all is done in subcommands
2075 // ----------------------------------------------------------------------------
2077 CommandSetInPortValue::CommandSetInPortValue(std::string node,
2080 : Command(), _node(node), _port(port), _value(value)
2082 DEBTRACE("CommandSetInPortValue::CommandSetInPortValue " << node << " " << port << " " << value);
2086 std::string CommandSetInPortValue::dump()
2088 string ret ="CommandSetInPortValue " + _node + " " + _port + " " + _value;
2092 bool CommandSetInPortValue::localExecute()
2094 DEBTRACE("CommandSetInPortValue::localExecute");
2096 InputPresetPort *inpp = 0;
2097 InputStudyPort *insp = 0;
2098 DataNode *dnode = 0;
2099 SubjectDataPort *sinp = 0;
2102 Proc* proc = GuiContext::getCurrent()->getProc();
2103 Node* node = proc->getChildByName(_node);
2104 inp = node->getInputPort(_port);
2105 inpp = dynamic_cast<InputPresetPort*>(inp);
2106 insp = dynamic_cast<InputStudyPort*>(inp);
2107 dnode = dynamic_cast<DataNode*>(node);
2108 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2109 sinp = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2111 catch (Exception& ex)
2113 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2121 _oldValue = insp->getAsString();
2122 DEBTRACE("old value="<< _oldValue);
2123 dnode->setData(insp, _value );
2124 sinp->update(SETVALUE, 0, sinp);
2129 PyGILState_STATE gstate = PyGILState_Ensure();
2132 _oldValue = inp->getAsString();
2133 if (_oldValue == "None") _oldValue = "";
2134 DEBTRACE("old value="<< _oldValue);
2136 if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2137 strval = "\"" + _value + "\"";
2140 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2141 inp->edInit("Python", result);
2144 PyGILState_Release(gstate);
2145 sinp->update(SETVALUE, 0, sinp);
2148 catch (Exception& ex)
2150 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2151 //Py_DECREF(result);
2152 PyGILState_Release(gstate);
2158 bool CommandSetInPortValue::localReverse()
2160 DEBTRACE("CommandSetInPortValue::localReverse");
2162 InputPresetPort *inpp = 0;
2163 InputStudyPort *insp = 0;
2164 DataNode *dnode = 0;
2165 SubjectDataPort *sinp = 0;
2168 Proc* proc = GuiContext::getCurrent()->getProc();
2169 Node* node = proc->getChildByName(_node);
2170 inp = node->getInputPort(_port);
2171 inpp = dynamic_cast<InputPresetPort*>(inp);
2172 insp = dynamic_cast<InputStudyPort*>(inp);
2173 dnode = dynamic_cast<DataNode*>(node);
2174 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(inp));
2175 sinp = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2177 catch (Exception& ex)
2179 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2187 _value = insp->getAsString();
2188 DEBTRACE("value="<< _value);
2189 DEBTRACE("old value="<< _oldValue);
2190 dnode->setData(insp, _oldValue );
2191 sinp->update(SETVALUE, 0, sinp);
2195 PyObject *result = Py_None;
2196 PyGILState_STATE gstate = PyGILState_Ensure();
2199 _value = inp->getAsString();
2200 DEBTRACE("value="<< _value);
2201 DEBTRACE("old value="<< _oldValue);
2202 if (!_oldValue.empty())
2205 if (inp->edGetType()->kind() == YACS::ENGINE::String || inp->edGetType()->isA(Runtime::_tc_file))
2206 strval = "\"" + _oldValue + "\"";
2209 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2211 inp->edInit("Python", result);
2213 PyGILState_Release(gstate);
2214 sinp->update(SETVALUE, 0, sinp);
2217 catch (Exception& ex)
2219 DEBTRACE("CommandSetInPortValue::localExecute() : " << ex.what());
2220 //Py_DECREF(result);
2221 PyGILState_Release(gstate);
2227 // ----------------------------------------------------------------------------
2229 CommandSetOutPortValue::CommandSetOutPortValue(std::string node,
2232 : Command(), _node(node), _port(port), _value(value)
2234 DEBTRACE("CommandSetOutPortValue::CommandSetOutPortValue " << node << " " << port << " " << value);
2238 std::string CommandSetOutPortValue::dump()
2240 string ret ="CommandSetOutPortValue " + _node + " " + _port + " " + _value;
2244 bool CommandSetOutPortValue::localExecute()
2246 DEBTRACE("CommandSetOutPortValue::localExecute");
2247 OutputPresetPort *outpp = 0;
2248 OutputStudyPort *outsp = 0;
2249 DataNode *dnode = 0;
2250 SubjectDataPort *soutp = 0;
2253 Proc* proc = GuiContext::getCurrent()->getProc();
2254 Node* node = proc->getChildByName(_node);
2255 OutputPort* outp = node->getOutputPort(_port);
2256 outpp = dynamic_cast<OutputPresetPort*>(outp);
2257 outsp = dynamic_cast<OutputStudyPort*>(outp);
2258 dnode = dynamic_cast<DataNode*>(node);
2259 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2260 soutp = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2262 catch (Exception& ex)
2264 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2269 if (!outpp && !outsp)
2271 DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2272 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2278 DEBTRACE("Set value on output port only possible on a dataNode");
2279 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2286 _oldValue = outsp->getAsString();
2287 DEBTRACE("old value="<< _oldValue);
2288 dnode->setData(outsp, _value );
2289 soutp->update(SETVALUE, 0, soutp);
2296 _oldValue = outpp->getAsString();
2297 if (_oldValue == "None") _oldValue = "";
2298 DEBTRACE("old value="<< _oldValue);
2300 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2301 strval = "\"" + _value + "\"";
2304 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2306 catch (Exception& ex)
2308 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2314 PyGILState_STATE gstate = PyGILState_Ensure();
2317 DEBTRACE(PyObject_Str(result));
2318 val = convertPyObjectXml(outpp->edGetType(), result);
2320 dnode->setData(outpp, val );
2321 soutp->update(SETVALUE, 0, soutp);
2323 catch (Exception& ex)
2325 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2328 PyGILState_Release(gstate);
2333 PyGILState_Release(gstate);
2337 bool CommandSetOutPortValue::localReverse()
2339 DEBTRACE("CommandSetOutPortValue::localReverse");
2340 OutputPresetPort *outpp = 0;
2341 OutputStudyPort *outsp = 0;
2342 DataNode *dnode = 0;
2343 SubjectDataPort *soutp = 0;
2346 Proc* proc = GuiContext::getCurrent()->getProc();
2347 Node* node = proc->getChildByName(_node);
2348 OutputPort* outp = node->getOutputPort(_port);
2349 outpp = dynamic_cast<OutputPresetPort*>(outp);
2350 outsp = dynamic_cast<OutputStudyPort*>(outp);
2351 dnode = dynamic_cast<DataNode*>(node);
2352 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(outp));
2353 soutp = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2355 catch (Exception& ex)
2357 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2362 if (!outpp && !outsp)
2364 DEBTRACE("Set value on output port only possible on a presetPort or a studyPort");
2365 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a presetPort or a studyPort";
2371 DEBTRACE("Set value on output port only possible on a dataNode");
2372 GuiContext::getCurrent()->_lastErrorMessage = "Set value on output port only possible on a dataNode";
2379 _value = outsp->getAsString();
2380 DEBTRACE("value="<< _value);
2381 DEBTRACE("old value="<< _oldValue);
2382 dnode->setData(outsp, _oldValue );
2383 soutp->update(SETVALUE, 0, soutp);
2387 PyObject *result = Py_None;
2390 _value = outpp->getAsString();
2391 DEBTRACE("value="<< _value);
2392 DEBTRACE("old value="<< _oldValue);
2393 if (!_oldValue.empty())
2396 if (outpp->edGetType()->kind() == YACS::ENGINE::String || outpp->edGetType()->isA(Runtime::_tc_file))
2397 strval = "\"" + _value + "\"";
2400 result = YACS::ENGINE::getSALOMERuntime()->convertStringToPyObject(strval.c_str());
2403 catch (Exception& ex)
2405 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2411 PyGILState_STATE gstate = PyGILState_Ensure();
2414 DEBTRACE(PyObject_Str(result));
2415 val = convertPyObjectXml(outpp->edGetType(), result);
2417 dnode->setData(outpp, val );
2418 soutp->update(SETVALUE, 0, soutp);
2420 catch (Exception& ex)
2422 DEBTRACE("CommandSetOutPortValue::localExecute() : " << ex.what());
2425 PyGILState_Release(gstate);
2430 PyGILState_Release(gstate);
2434 // ----------------------------------------------------------------------------
2436 CommandSetSwitchSelect::CommandSetSwitchSelect(std::string aSwitch,
2438 : Command(), _switch(aSwitch), _value(value)
2440 DEBTRACE("CommandSetSwitchSelect::CommandSetSwitchSelect");
2444 std::string CommandSetSwitchSelect::dump()
2446 string ret ="CommandSetSwitchSelect " + _switch + " " + _value;
2450 bool CommandSetSwitchSelect::localExecute()
2452 DEBTRACE("CommandSetSwitchSelect::localExecute");
2455 Proc* proc = GuiContext::getCurrent()->getProc();
2456 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2457 InputPort *condPort = aSwitch->edGetConditionPort();
2458 _oldValue = condPort->getAsString();
2459 if (_oldValue == "None") _oldValue = "0";
2460 int val = atoi(_value.c_str());
2461 condPort->edInit(val);
2462 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2463 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2464 snode->update(SETSELECT, 0, snode);
2466 catch (Exception& ex)
2468 DEBTRACE("CommandSetSwitchSelect::localExecute() : " << ex.what());
2474 bool CommandSetSwitchSelect::localReverse()
2476 DEBTRACE("CommandSetSwitchSelect::localReverse");
2479 Proc* proc = GuiContext::getCurrent()->getProc();
2480 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2481 InputPort *condPort = aSwitch->edGetConditionPort();
2482 int val = atoi(_oldValue.c_str());
2483 condPort->edInit(val);
2484 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2485 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2486 snode->update(SETSELECT, 0, snode);
2488 catch (Exception& ex)
2490 DEBTRACE("CommandSetSwitchSelect::localReverse() : " << ex.what());
2496 // ----------------------------------------------------------------------------
2498 CommandSetSwitchCase::CommandSetSwitchCase(std::string aSwitch,
2501 : Command(), _switch(aSwitch), _node(node), _value(value)
2503 DEBTRACE("CommandSetSwitchCase::CommandSetSwitchCase");
2508 std::string CommandSetSwitchCase::dump()
2510 string ret ="CommandSetSwitchCase " + _switch + " " + _node + " " + _value;
2514 bool CommandSetSwitchCase::localExecute()
2516 DEBTRACE("CommandSetSwitchCase::localExecute");
2519 DEBTRACE("CommandSetSwitchCase::localExecute");
2520 Proc* proc = GuiContext::getCurrent()->getProc();
2521 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2522 Node* node = proc->getChildByName(_node);
2523 int val = atoi(_value.c_str());
2524 if (aSwitch->edGetNode(val))
2526 throw YACS::Exception("Set Switch Case impossible: value already used");
2528 int oldVal = aSwitch->getRankOfNode(node);
2529 aSwitch->edChangeCase(oldVal,val);
2531 _oldNode = proc->getChildName(node);
2532 DEBTRACE("CommandSetSwitchCase::localExecute OK " << val);
2533 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2534 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2535 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2536 ssw->update(SETCASE, val, snode);
2537 snode->recursiveUpdate(RENAME, 0, snode);
2540 catch (Exception& ex)
2542 DEBTRACE("CommandSetSwitchCase::localExecute() : " << ex.what());
2548 bool CommandSetSwitchCase::localReverse()
2550 DEBTRACE("CommandSetSwitchCase::localReverse");
2553 DEBTRACE("CommandSetSwitchCase::localReverse");
2554 Proc* proc = GuiContext::getCurrent()->getProc();
2555 Switch* aSwitch = dynamic_cast<Switch*>(proc->getChildByName(_switch));
2556 Node* node = proc->getChildByName(_oldNode);
2557 int val = _oldValue;
2558 if (aSwitch->edGetNode(val))
2560 throw YACS::Exception("Set Switch Case impossible: value already used");
2562 int oldVal = aSwitch->getRankOfNode(node);
2563 aSwitch->edChangeCase(oldVal,val);
2564 DEBTRACE("CommandSetSwitchCase::localReverse OK " << val);
2565 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(aSwitch));
2566 SubjectNode *ssw = GuiContext::getCurrent()->_mapOfSubjectNode[aSwitch];
2567 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2568 ssw->update(SETCASE, val, snode);
2569 snode->recursiveUpdate(RENAME, 0, snode);
2572 catch (Exception& ex)
2574 DEBTRACE("CommandSetSwitchCase::localReverse() : " << ex.what());
2580 // ----------------------------------------------------------------------------
2582 CommandSetForLoopSteps::CommandSetForLoopSteps(std::string forLoop,
2584 : Command(), _forLoop(forLoop), _value(value)
2586 DEBTRACE("CommandSetForLoopSteps::CommandSetForLoopSteps");
2591 std::string CommandSetForLoopSteps::dump()
2593 string ret ="CommandSetForLoopSteps " + _forLoop + " " + _value;
2597 bool CommandSetForLoopSteps::localExecute()
2599 DEBTRACE("CommandSetForLoopSteps::localExecute");
2602 DEBTRACE("CommandSetForLoopSteps::localExecute");
2603 Proc* proc = GuiContext::getCurrent()->getProc();
2604 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2605 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2606 _oldValue = atoi(forLoop->edGetNbOfTimesInputPort()->getAsString().c_str());
2607 int val = atoi(_value.c_str());
2608 nbSteps->edInit(val);
2609 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2610 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2611 snode->update(SETVALUE, 0, snode);
2614 catch (Exception& ex)
2616 DEBTRACE("CommandSetForLoopSteps::localExecute() : " << ex.what());
2622 bool CommandSetForLoopSteps::localReverse()
2624 DEBTRACE("CommandSetForLoopSteps::localReverse");
2627 DEBTRACE("CommandSetForLoopSteps::localReverse");
2628 Proc* proc = GuiContext::getCurrent()->getProc();
2629 ForLoop* forLoop = dynamic_cast<ForLoop*>(proc->getChildByName(_forLoop));
2630 InputPort *nbSteps = forLoop->edGetNbOfTimesInputPort();
2631 nbSteps->edInit(_oldValue);
2632 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(forLoop));
2633 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[forLoop];
2634 snode->update(SETVALUE, 0, snode);
2637 catch (Exception& ex)
2639 DEBTRACE("CommandSetForLoopSteps::localReverse() : " << ex.what());
2645 // ----------------------------------------------------------------------------
2647 CommandSetWhileCondition::CommandSetWhileCondition(std::string whileLoop,
2649 : Command(), _whileLoop(whileLoop), _value(value)
2651 DEBTRACE("CommandSetWhileCondition::CommandSetWhileCondition");
2655 std::string CommandSetWhileCondition::dump()
2657 string ret ="CommandSetWhileCondition " + _whileLoop + " " + _value;
2661 bool CommandSetWhileCondition::localExecute()
2663 DEBTRACE("CommandSetWhileCondition::localExecute");
2666 Proc* proc = GuiContext::getCurrent()->getProc();
2667 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2668 InputPort *cond = whileLoop->edGetConditionPort();
2669 _oldValue = atoi(whileLoop->edGetConditionPort()->getAsString().c_str());
2670 bool val = atoi(_value.c_str());
2672 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2673 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2674 snode->update(SETVALUE, 0, snode);
2677 catch (Exception& ex)
2679 DEBTRACE("CommandSetWhileCondition::localExecute() : " << ex.what());
2685 bool CommandSetWhileCondition::localReverse()
2687 DEBTRACE("CommandSetWhileCondition::localReverse");
2690 Proc* proc = GuiContext::getCurrent()->getProc();
2691 WhileLoop* whileLoop = dynamic_cast<WhileLoop*>(proc->getChildByName(_whileLoop));
2692 InputPort *cond = whileLoop->edGetConditionPort();
2693 cond->edInit(_oldValue);
2694 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(whileLoop));
2695 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[whileLoop];
2696 snode->update(SETVALUE, 0, snode);
2699 catch (Exception& ex)
2701 DEBTRACE("CommandSetWhileCondition::localReverse() : " << ex.what());
2707 // ----------------------------------------------------------------------------
2709 CommandSetForEachBranch::CommandSetForEachBranch(std::string forEach,
2711 : Command(), _forEach(forEach), _value(value)
2713 DEBTRACE("CommandSetForEachBranch::CommandSetForEachBranch");
2717 std::string CommandSetForEachBranch::dump()
2719 string ret ="CommandSetForEachBranch " + _forEach + " " + _value;
2723 bool CommandSetForEachBranch::localExecute()
2725 DEBTRACE("CommandSetForEachBranch::localExecute");
2728 Proc* proc = GuiContext::getCurrent()->getProc();
2729 Node* node=proc->getChildByName(_forEach);
2730 InputPort *nbBranches = node->getInputPort("nbBranches");
2731 _oldValue = atoi(nbBranches->getAsString().c_str());
2732 int val = atoi(_value.c_str());
2733 nbBranches->edInit(val);
2734 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2735 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2736 spo->update(SETVALUE, 0, spo);
2737 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2738 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2739 snode->update(SETVALUE, 0, snode);
2742 catch (Exception& ex)
2744 DEBTRACE("CommandSetForEachBranch::localExecute() : " << ex.what());
2750 bool CommandSetForEachBranch::localReverse()
2752 DEBTRACE("CommandSetForEachBranch::localReverse");
2755 Proc* proc = GuiContext::getCurrent()->getProc();
2756 Node* node=proc->getChildByName(_forEach);
2757 InputPort *nbBranches = node->getInputPort("nbBranches");
2758 nbBranches->edInit(_oldValue);
2759 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(nbBranches));
2760 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(nbBranches)];
2761 spo->update(SETVALUE, 0, spo);
2762 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
2763 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
2764 snode->update(SETVALUE, 0, snode);
2767 catch (Exception& ex)
2769 DEBTRACE("CommandSetForEachBranch::localReverse() : " << ex.what());
2775 // ----------------------------------------------------------------------------
2777 CommandSetAlgo::CommandSetAlgo(std::string optimizer, std::string alglib, std::string symbol)
2778 : Command(), _optimizer(optimizer), _alglib(alglib), _symbol(symbol)
2780 DEBTRACE("CommandSetAlgo::CommandSetAlgo" << _optimizer << " " << _alglib << " " << _symbol);
2785 std::string CommandSetAlgo::dump()
2787 string ret ="CommandSetAlgo " + _optimizer + " " + _alglib + " " + _symbol;
2791 bool CommandSetAlgo::localExecute()
2793 DEBTRACE("CommandSetAlgo::localExecute");
2796 Proc* proc = GuiContext::getCurrent()->getProc();
2797 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2798 loop->setAlgorithm(_alglib,_symbol);
2799 _oldAlglib = _alglib;
2800 _oldSymbol = _symbol;
2801 InputPort *port = loop->edGetPortForOutPool();
2802 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2803 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2804 spo->update(UPDATE, 0, spo);
2805 OutputPort *oport = loop->edGetSamplePort();
2806 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2807 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2808 spo->update(UPDATE, 0, spo);
2809 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2810 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2811 snode->update(SETVALUE, 0, snode);
2814 catch (Exception& ex)
2816 DEBTRACE("CommandSetAlgo::localExecute() : " << ex.what());
2822 bool CommandSetAlgo::localReverse()
2824 DEBTRACE("CommandSetAlgo::localReverse");
2827 Proc* proc = GuiContext::getCurrent()->getProc();
2828 OptimizerLoop* loop = dynamic_cast<OptimizerLoop*>(proc->getChildByName(_optimizer));
2829 loop->setAlgorithm(_oldAlglib,_oldSymbol);
2830 InputPort *port = loop->edGetPortForOutPool();
2831 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(port)));
2832 SubjectDataPort *spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(port)];
2833 spo->update(UPDATE, 0, spo);
2834 OutputPort *oport = loop->edGetSamplePort();
2835 YASSERT(GuiContext::getCurrent()->_mapOfSubjectDataPort.count(static_cast<DataPort*>(oport)));
2836 spo = GuiContext::getCurrent()->_mapOfSubjectDataPort[static_cast<DataPort*>(oport)];
2837 spo->update(UPDATE, 0, spo);
2838 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(loop));
2839 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[loop];
2840 snode->update(SETVALUE, 0, snode);
2843 catch (Exception& ex)
2845 DEBTRACE("CommandSetAlgo::localReverse() : " << ex.what());
2852 // ----------------------------------------------------------------------------
2854 CommandAddLink::CommandAddLink(std::string outNode, std::string outPort, TypeOfElem outPortType,
2855 std::string inNode, std::string inPort, TypeOfElem inPortType, bool control)
2856 : Command(), _outNode(outNode), _outPort(outPort), _outPortType(outPortType),
2857 _inNode(inNode), _inPort(inPort), _inPortType(inPortType), _control(control)
2859 DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort<<" "<<control);
2860 _controlCreatedWithDF = false;
2863 std::string CommandAddLink::dump()
2866 if (_control) s = "true";
2867 string ret ="CommandAddLink " + _outNode + " " + _outPort + " " + _inNode + " " + _inPort + " " + s;
2871 bool CommandAddLink::localExecute()
2873 DEBTRACE("CommandAddLink::localExecute");
2874 DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort<<" "<<_control);
2877 Proc* proc = GuiContext::getCurrent()->getProc();
2878 Node* outn = proc->getChildByName(_outNode);
2879 Node* inn = proc->getChildByName(_inNode);
2883 // --- is a control link already existing ?
2884 bool preexistingControl = false;
2888 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn2,inn2);
2889 if(outn2==father || inn2==father)
2890 preexistingControl = true;
2893 while(outn2->getFather() != father)
2894 outn2 = outn2->getFather();
2895 while(inn2->getFather() != father)
2896 inn2 = inn2->getFather();
2897 OutGate *ogate = outn2->getOutGate();
2898 InGate *igate = inn2->getInGate();
2899 if (ogate->isAlreadyInSet(igate))
2900 preexistingControl = true;
2904 if(_outPortType == OUTPUTPORT)
2905 outp = outn->getOutputPort(_outPort);
2907 outp = outn->getOutputDataStreamPort(_outPort);
2909 if(_inPortType == INPUTPORT)
2910 inp = inn->getInputPort(_inPort);
2912 inp = inn->getInputDataStreamPort(_inPort);
2914 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
2915 DEBTRACE(cla->getName());
2916 if (dynamic_cast<OutputDataStreamPort*>(outp))
2917 cla->edAddLink(outp,inp);
2919 cla->edAddDFLink(outp,inp);
2921 cla->edAddLink(outp,inp);
2923 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
2924 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
2925 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
2926 DEBTRACE(scla->getName());
2927 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2928 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2929 SubjectDataPort *subOutport = GuiContext::getCurrent()->_mapOfSubjectDataPort[outp];
2930 SubjectDataPort *subInport = GuiContext::getCurrent()->_mapOfSubjectDataPort[inp];
2931 SubjectLink *slink = scla->addSubjectLink(sno, subOutport, sni, subInport);
2933 // --- if control link, identify the nodes linked and draw the control link if not already existing
2937 ComposedNode* father = ComposedNode::getLowestCommonAncestor(outn,inn);
2938 if(outn==father || inn==father) return true;
2939 while(outn->getFather() != father)
2940 outn = outn->getFather();
2941 while(inn->getFather() != father)
2942 inn = inn->getFather();
2943 OutGate *ogate = outn->getOutGate();
2944 InGate *igate = inn->getInGate();
2945 if (ogate->isAlreadyInSet(igate))
2947 if (!preexistingControl)
2948 _controlCreatedWithDF = true;
2949 pair<Node*,Node*> keyLink(outn,inn);
2950 if (!GuiContext::getCurrent()->_mapOfSubjectControlLink.count(keyLink))
2952 SubjectNode *sfno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
2953 SubjectNode *sfni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
2954 if (!sfno || !sfni) return true;
2955 SubjectControlLink *sclink = scla->addSubjectControlLink(sfno, sfni);
2961 catch (Exception& ex)
2963 DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
2969 bool CommandAddLink::localReverse()
2971 DEBTRACE("CommandAddLink::localReverse");
2974 SubjectLink *slink =0;
2975 SubjectControlLink *sclink = 0;
2976 Proc* proc = GuiContext::getCurrent()->getProc();
2977 Node* outn = proc->getChildByName(_outNode);
2978 Node* inn = proc->getChildByName(_inNode);
2981 if(_outPortType == OUTPUTPORT)
2982 outp = outn->getOutputPort(_outPort);
2984 outp = outn->getOutputDataStreamPort(_outPort);
2985 if(_inPortType == INPUTPORT)
2986 inp = inn->getInputPort(_inPort);
2988 inp = inn->getInputDataStreamPort(_inPort);
2989 YASSERT(GuiContext::getCurrent()->_mapOfSubjectLink.count(pair<OutPort*,InPort*>(outp,inp)));
2990 slink = GuiContext::getCurrent()->_mapOfSubjectLink[pair<OutPort*,InPort*>(outp,inp)];
2991 if (_controlCreatedWithDF)
2993 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
2994 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
2997 Subject *father = slink->getParent();
2998 Subject::erase(slink);
3003 father->select(true);
3004 father->update(REMOVE,0,0);
3008 father=sclink->getParent();
3009 Subject::erase(sclink);
3014 father->select(true);
3015 father->update(REMOVE,0,0);
3019 catch (Exception& ex)
3021 DEBTRACE("CommandAddLink::localReverse(): " << ex.what());
3027 // ----------------------------------------------------------------------------
3029 CommandAddControlLink::CommandAddControlLink(std::string outNode, std::string inNode)
3030 : Command(), _outNode(outNode), _inNode(inNode)
3032 DEBTRACE("CommandAddControlLink::CommandAddControlLink "<<outNode<<"-->>"<<inNode);
3035 std::string CommandAddControlLink::dump()
3037 string ret ="CommandAddControlLink " + _outNode + " " + _inNode;
3041 bool CommandAddControlLink::localExecute()
3043 DEBTRACE("CommandAddControlLink::localExecute");
3046 Proc* proc = GuiContext::getCurrent()->getProc();
3048 if (! _outNode.empty())
3049 outn = proc->getChildByName(_outNode);
3051 if (! _inNode.empty())
3052 inn = proc->getChildByName(_inNode);
3053 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn,inn);
3054 DEBTRACE(cla->getName());
3055 bool ret= cla->edAddCFLink(outn,inn);
3057 GuiContext::getCurrent()->_lastErrorMessage = "Link already exists";
3059 cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),
3061 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(cla));
3062 SubjectNode *sub = GuiContext::getCurrent()->_mapOfSubjectNode[cla];
3063 SubjectComposedNode *scla = dynamic_cast<SubjectComposedNode*>(sub);
3064 DEBTRACE(scla->getName());
3065 SubjectNode *sno = GuiContext::getCurrent()->_mapOfSubjectNode[outn];
3066 SubjectNode *sni = GuiContext::getCurrent()->_mapOfSubjectNode[inn];
3067 SubjectControlLink *sclink = scla->addSubjectControlLink(sno,sni);
3070 catch (Exception& ex)
3072 DEBTRACE("CommandAddControlLink::localExecute() : " << ex.what());
3078 bool CommandAddControlLink::localReverse()
3080 DEBTRACE("CommandAddControlLink::localReverse");
3083 SubjectControlLink *sclink = 0;
3084 Proc* proc = GuiContext::getCurrent()->getProc();
3085 Node* outn = proc->getChildByName(_outNode);
3086 Node* inn = proc->getChildByName(_inNode);
3087 YASSERT(GuiContext::getCurrent()->_mapOfSubjectControlLink.count(pair<Node*,Node*>(outn,inn)));
3088 sclink = GuiContext::getCurrent()->_mapOfSubjectControlLink[pair<Node*,Node*>(outn,inn)];
3090 Subject *father=sclink->getParent();
3091 Subject::erase(sclink);
3096 father->select(true);
3097 father->update(REMOVE,0,0);
3101 catch (Exception& ex)
3103 DEBTRACE("CommandAddControlLink::localReverse(): " << ex.what());
3109 // ----------------------------------------------------------------------------
3111 CommandAddContainer::CommandAddContainer(std::string name,
3112 std::string refContainer)
3113 : Command(), _name(name), _containerToClone(refContainer), _subcont(0)
3115 DEBTRACE("CommandAddContainer::CommandAddContainer " << name << " " << refContainer);
3118 std::string CommandAddContainer::dump()
3120 string ret ="CommandAddContainer " + _name + " " + _containerToClone;
3124 bool CommandAddContainer::localExecute()
3126 DEBTRACE("CommandAddContainer::localExecute");
3129 Proc* proc = GuiContext::getCurrent()->getProc();
3130 if (proc->containerMap.count(_name))
3132 GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
3135 Container *container = new SalomeContainer();
3136 if (! _containerToClone.empty())
3138 if (proc->containerMap.count(_containerToClone))
3140 Container *ref = proc->containerMap[_containerToClone];
3142 container->setProperties(ref->getProperties());
3146 GuiContext::getCurrent()->_lastErrorMessage = "There is no reference container to clone properties";
3150 container->setName(_name);
3151 container->setProc(proc);
3152 proc->containerMap[_name] = container;
3154 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3155 _subcont = sproc->addSubjectContainer(container, _name);
3158 catch (Exception& ex)
3160 DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
3166 bool CommandAddContainer::localReverse()
3168 DEBTRACE("CommandAddContainer::localReverse");
3171 Proc* proc = GuiContext::getCurrent()->getProc();
3172 YASSERT(proc->containerMap.count(_name));
3173 Container *container = proc->containerMap[_name];
3174 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(container));
3175 _subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[container];
3176 YASSERT(!_subcont->isUsed());
3177 SubjectProc* sproc = GuiContext::getCurrent()->getSubjectProc();
3178 sproc->removeSubjectContainer(_subcont);
3181 catch (Exception& ex)
3183 DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
3189 // ----------------------------------------------------------------------------
3191 CommandSetNodeProperties::CommandSetNodeProperties(std::string position, std::map<std::string,std::string> properties)
3192 : Command(), _position(position), _properties(properties)
3194 DEBTRACE("CommandSetNodeProperties::CommandSetNodeProperties " << position);
3198 std::string CommandSetNodeProperties::dump()
3200 string ret ="CommandSetNodeProperties " + _position;
3204 bool CommandSetNodeProperties::localExecute()
3206 DEBTRACE("CommandSetNodeProperties::localExecute");
3209 Proc* proc = GuiContext::getCurrent()->getProc();
3212 if (!_position.empty()) node = proc->getChildByName(_position);
3216 _oldProp = node->getPropertyMap();
3217 node->setProperties(_properties);
3218 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3219 snode->update(SETVALUE, 0, snode);
3222 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3225 catch (Exception& ex)
3227 DEBTRACE("CommandSetNodeProperties::localExecute() : " << ex.what());
3233 bool CommandSetNodeProperties::localReverse()
3235 DEBTRACE("CommandSetNodeProperties::localReverse");
3238 Proc* proc = GuiContext::getCurrent()->getProc();
3241 if (!_position.empty()) node = proc->getChildByName(_position);
3245 node->setProperties(_oldProp);
3246 SubjectNode *snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3247 snode->update(SETVALUE, 0, snode);
3250 GuiContext::getCurrent()->_lastErrorMessage = "node not found: " + _position;
3253 catch (Exception& ex)
3255 DEBTRACE("CommandSetNodeProperties::localReverse() : " << ex.what());
3261 // ----------------------------------------------------------------------------
3263 CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties(std::string compoinstance,
3264 std::map<std::string,std::string> properties)
3265 : Command(), _compoinstance(compoinstance), _properties(properties)
3267 DEBTRACE("CommandSetComponentInstanceProperties::CommandSetComponentInstanceProperties " << compoinstance);
3271 std::string CommandSetComponentInstanceProperties::dump()
3273 string ret ="CommandSetComponentInstanceProperties " + _compoinstance;
3277 bool CommandSetComponentInstanceProperties::localExecute()
3279 DEBTRACE("CommandSetComponentInstanceProperties::localExecute");
3282 Proc* proc = GuiContext::getCurrent()->getProc();
3283 if (proc->componentInstanceMap.count(_compoinstance))
3285 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3287 _oldProp = ref->getProperties();
3288 _oldAnon = ref->isAnonymous();
3289 ref->setProperties(_properties);
3290 ref->setAnonymous(false);
3291 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3292 subcompo->update(SETVALUE, 0, subcompo);
3295 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3298 catch (Exception& ex)
3300 DEBTRACE("CommandSetComponentInstanceProperties::localExecute() : " << ex.what());
3306 bool CommandSetComponentInstanceProperties::localReverse()
3308 DEBTRACE("CommandSetComponentInstanceProperties::localReverse");
3311 Proc* proc = GuiContext::getCurrent()->getProc();
3312 if (proc->componentInstanceMap.count(_compoinstance))
3314 ComponentInstance *ref = proc->componentInstanceMap[_compoinstance];
3316 ref->setProperties(_oldProp);
3317 ref->setAnonymous(_oldAnon);
3318 SubjectComponent* subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[ref];
3319 subcompo->update(SETVALUE, 0, subcompo);
3322 GuiContext::getCurrent()->_lastErrorMessage = "compoinstance not found: " + _compoinstance;
3325 catch (Exception& ex)
3327 DEBTRACE("CommandSetComponentInstanceProperties::localReverse() : " << ex.what());
3333 // ----------------------------------------------------------------------------
3335 CommandSetContainerProperties::CommandSetContainerProperties(std::string container,
3336 std::map<std::string,std::string> properties)
3337 : Command(), _container(container), _properties(properties)
3339 DEBTRACE("CommandSetContainerProperties::CommandSetContainerProperties " << container);
3343 std::string CommandSetContainerProperties::dump()
3345 string ret ="CommandSetContainerProperties " + _container;
3349 bool CommandSetContainerProperties::localExecute()
3351 DEBTRACE("CommandSetContainerProperties::localExecute");
3354 Proc* proc = GuiContext::getCurrent()->getProc();
3355 if (proc->containerMap.count(_container))
3357 Container *ref = proc->containerMap[_container];
3359 _oldProp = ref->getProperties();
3360 ref->setProperties(_properties);
3363 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3366 catch (Exception& ex)
3368 DEBTRACE("CommandSetContainerProperties::localExecute() : " << ex.what());
3374 bool CommandSetContainerProperties::localReverse()
3376 DEBTRACE("CommandSetContainerProperties::localReverse");
3379 Proc* proc = GuiContext::getCurrent()->getProc();
3380 if (proc->containerMap.count(_container))
3382 Container *ref = proc->containerMap[_container];
3384 ref->setProperties(_oldProp);
3387 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
3390 catch (Exception& ex)
3392 DEBTRACE("CommandSetContainerProperties::localReverse() : " << ex.what());
3398 // ----------------------------------------------------------------------------
3400 CommandSetDSPortProperties::CommandSetDSPortProperties(std::string node, std::string port, bool isInport,
3401 std::map<std::string,std::string> properties)
3402 : Command(), _nodeName(node), _portName(port), _isInport(isInport), _properties(properties)
3404 DEBTRACE("CommandSetDSPortProperties::CommandSetDSPortProperties " << node << "." << port << " " << isInport);
3408 std::string CommandSetDSPortProperties::dump()
3411 if (_isInport) s = "true";
3412 string ret ="CommandSetDSPortProperties " + _nodeName + " " + _portName + " " + s;
3416 bool CommandSetDSPortProperties::localExecute()
3418 DEBTRACE("CommandSetDSPortProperties::localExecute");
3421 Proc* proc = GuiContext::getCurrent()->getProc();
3422 Node* node = proc->getChildByName(_nodeName);
3423 DataStreamPort* DSPort = 0;
3425 DSPort = node->getInputDataStreamPort(_portName);
3427 DSPort = node->getOutputDataStreamPort(_portName);
3428 _oldProp = DSPort->getProperties();
3429 DSPort->setProperties(_properties);
3432 catch (Exception& ex)
3434 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3440 bool CommandSetDSPortProperties::localReverse()
3442 DEBTRACE("CommandSetDSPortProperties::localReverse");
3445 Proc* proc = GuiContext::getCurrent()->getProc();
3446 Node* node = proc->getChildByName(_nodeName);
3447 DataStreamPort* DSPort = 0;
3449 DSPort = node->getInputDataStreamPort(_portName);
3451 DSPort = node->getOutputDataStreamPort(_portName);
3452 DSPort->setProperties(_oldProp);
3455 catch (Exception& ex)
3457 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3463 // ----------------------------------------------------------------------------
3465 CommandSetLinkProperties::CommandSetLinkProperties(std::string startnode, std::string startport,
3466 std::string endnode, std::string endport,
3467 std::map<std::string,std::string> properties)
3468 : Command(), _startNodeName(startnode), _startPortName(startport),
3469 _endNodeName(endnode), _endPortName(endport),
3470 _properties(properties)
3472 DEBTRACE("CommandSetLinkProperties::CommandSetLinkProperties " );
3476 std::string CommandSetLinkProperties::dump()
3478 string ret ="CommandSetLinkProperties " + _startNodeName + " " + _startPortName + " " + _endNodeName + " " + _endPortName;
3482 bool CommandSetLinkProperties::localExecute()
3484 DEBTRACE("CommandSetLinkProperties::localExecute");
3487 Proc* proc = GuiContext::getCurrent()->getProc();
3489 InputDataStreamPort* inDSPort = 0;
3490 OutputDataStreamPort* outDSPort = 0;
3492 node = proc->getChildByName(_startNodeName);
3493 outDSPort = node->getOutputDataStreamPort(_startPortName);
3494 outDSPort->setProperties(_properties);
3496 node = proc->getChildByName(_endNodeName);
3497 inDSPort = node->getInputDataStreamPort(_endPortName);
3498 _oldProp = inDSPort->getProperties();
3499 inDSPort->setProperties(_properties);
3501 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3502 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3503 subject->update(SETVALUE, 0, subject);
3506 catch (Exception& ex)
3508 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
3514 bool CommandSetLinkProperties::localReverse()
3516 DEBTRACE("CommandSetLinkProperties::localReverse");
3519 Proc* proc = GuiContext::getCurrent()->getProc();
3521 InputDataStreamPort* inDSPort = 0;
3522 OutputDataStreamPort* outDSPort = 0;
3524 node = proc->getChildByName(_startNodeName);
3525 outDSPort = node->getOutputDataStreamPort(_startPortName);
3526 outDSPort->setProperties(_properties);
3528 node = proc->getChildByName(_endNodeName);
3529 inDSPort = node->getInputDataStreamPort(_endPortName);
3530 inDSPort->setProperties(_oldProp);
3532 std::pair<OutPort*,InPort*> keymap = std::pair<OutPort*,InPort*>(outDSPort,inDSPort);
3533 SubjectLink* subject = GuiContext::getCurrent()->_mapOfSubjectLink[keymap];
3534 subject->update(SETVALUE, 0, subject);
3537 catch (Exception& ex)
3539 DEBTRACE("CommandSetDSPortProperties::localReverse() : " << ex.what());
3545 // ----------------------------------------------------------------------------
3547 CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName(std::string node, std::string funcName)
3548 : Command(), _nodeName(node), _funcName(funcName)
3550 DEBTRACE("CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName " << node << " " <<funcName);
3554 std::string CommandSetFuncNodeFunctionName::dump()
3556 string ret ="CommandSetFuncNodeFunctionName " + _nodeName + " " + _funcName;
3560 bool CommandSetFuncNodeFunctionName::localExecute()
3562 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute");
3565 Proc* proc = GuiContext::getCurrent()->getProc();
3566 Node* node = proc->getChildByName(_nodeName);
3567 if (_funcName.empty())
3569 GuiContext::getCurrent()->_lastErrorMessage = "InlineFuncNode function name empty: " + _nodeName;
3572 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3574 _oldName = funcNode->getFname();
3575 funcNode->setFname(_funcName);
3580 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3584 catch (Exception& ex)
3586 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute() : " << ex.what());
3592 bool CommandSetFuncNodeFunctionName::localReverse()
3594 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse");
3597 Proc* proc = GuiContext::getCurrent()->getProc();
3598 Node* node = proc->getChildByName(_nodeName);
3599 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
3601 funcNode->setFname(_oldName);
3606 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
3610 catch (Exception& ex)
3612 DEBTRACE("CommandSetFuncNodeFunctionName::localReverse() : " << ex.what());
3618 // ----------------------------------------------------------------------------
3620 CommandSetInlineNodeScript::CommandSetInlineNodeScript(std::string node, std::string script)
3621 : Command(), _nodeName(node), _script(script)
3623 DEBTRACE("CommandSetInlineNodeScript::CommandSetInlineNodeScript " << node << " " <<script);
3627 std::string CommandSetInlineNodeScript::dump()
3629 string ret ="CommandSetInlineNodeScript " + _nodeName;
3633 bool CommandSetInlineNodeScript::localExecute()
3635 DEBTRACE("CommandSetInlineNodeScript::localExecute");
3638 Proc* proc = GuiContext::getCurrent()->getProc();
3639 Node* node = proc->getChildByName(_nodeName);
3640 if (_script.empty())
3642 GuiContext::getCurrent()->_lastErrorMessage = "InlineNode script empty: " + _nodeName;
3645 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3647 _oldScript = inlineNode->getScript();
3648 inlineNode->setScript(_script);
3649 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3650 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3651 snode->update(SYNCHRO,0,snode);
3656 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3660 catch (Exception& ex)
3662 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3668 bool CommandSetInlineNodeScript::localReverse()
3670 DEBTRACE("CommandSetInlineNodeScript::localReverse");
3673 Proc* proc = GuiContext::getCurrent()->getProc();
3674 Node* node = proc->getChildByName(_nodeName);
3675 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3677 inlineNode->setScript(_oldScript);
3678 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
3679 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
3680 snode->update(SYNCHRO,0,snode);
3685 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3689 catch (Exception& ex)
3691 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
3697 // ----------------------------------------------------------------------------
3699 CommandAddComponentInstance::CommandAddComponentInstance(std::string compoName,
3700 std::string container,
3702 : Command(), _compoName(compoName), _container(container), _name(name), _subcompo(0)
3704 DEBTRACE("CommandAddComponentInstance::CommandAddComponentInstance " <<_compoName);
3707 std::string CommandAddComponentInstance::dump()
3709 string ret ="CommandAddComponentInstance " + _compoName + " " + _container + " " + _name;
3713 bool CommandAddComponentInstance::localExecute()
3715 DEBTRACE("CommandAddComponentInstance::localExecute "<< _compoName << " " << _container << " " << _name);
3718 Proc* proc = GuiContext::getCurrent()->getProc();
3719 YASSERT(proc->containerMap.count(_container));
3720 Container *cont = proc->containerMap[_container];
3721 ComponentInstance* compoInst = new SalomeComponent(_compoName);
3722 compoInst->setContainer(cont);
3723 proc->addComponentInstance(compoInst, _name);
3725 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
3726 _subcompo = sproc->addSubjectComponent(compoInst);
3727 _name = compoInst->getInstanceName();
3731 catch (Exception& ex)
3733 DEBTRACE("CommandAddComponentInstance::localExecute() : " << ex.what());
3739 bool CommandAddComponentInstance::localReverse()
3741 DEBTRACE("CommandAddComponentInstance::localReverse");
3744 Proc* proc = GuiContext::getCurrent()->getProc();
3745 YASSERT(proc->componentInstanceMap.count(_name));
3746 ComponentInstance *compo = proc->componentInstanceMap[_name];
3747 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
3748 _subcompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
3749 YASSERT(!_subcompo->hasServices());
3750 Container *cont = compo->getContainer();
3751 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
3752 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3753 subcont->detachComponent(_subcompo);
3754 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
3755 proc->removeComponentInstance(compo);
3758 catch (Exception& ex)
3760 DEBTRACE("CommandAddComponentInstance::localReverse() : " << ex.what());
3766 // ----------------------------------------------------------------------------
3767 CommandSetExecutionMode::CommandSetExecutionMode(std::string nodeName, std::string mode)
3768 : Command(), _mode(mode),_nodeName(nodeName)
3770 DEBTRACE("CommandSetExecutionMode::CommandSetExecutionMode " << nodeName << " " << mode);
3774 std::string CommandSetExecutionMode::dump()
3776 string ret ="CommandSetExecutionMode " + _mode + " " + _nodeName;
3780 bool CommandSetExecutionMode::localExecute()
3782 DEBTRACE("CommandSetExecutionMode::localExecute");
3785 Proc* proc = GuiContext::getCurrent()->getProc();
3786 Node* node = proc->getChildByName(_nodeName);
3787 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3789 _oldmode = pyNode->getExecutionMode();
3790 pyNode->setExecutionMode(_mode);
3791 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3792 snode->update(UPDATE, 0, 0);
3797 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3801 catch (Exception& ex)
3803 DEBTRACE("CommandSetExecutionMode::localExecute() : " << ex.what());
3809 bool CommandSetExecutionMode::localReverse()
3811 DEBTRACE("CommandSetExecutionMode::localReverse");
3814 if (_oldmode == _mode) return true;
3815 Proc* proc = GuiContext::getCurrent()->getProc();
3816 Node* node = proc->getChildByName(_nodeName);
3817 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3819 pyNode->setExecutionMode(_oldmode);
3820 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3821 snode->update(UPDATE, 0, 0);
3826 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3830 catch (Exception& ex)
3832 DEBTRACE("CommandSetExecutionMode::localReverse() : " << ex.what());
3840 // ----------------------------------------------------------------------------
3842 CommandSetContainer::CommandSetContainer(std::string nodeName, std::string container)
3843 : Command(), _container(container),_nodeName(nodeName)
3845 DEBTRACE("CommandSetContainer::CommandSetContainer " << nodeName << " " << container);
3846 _oldcont = "DefaultContainer";
3849 std::string CommandSetContainer::dump()
3851 string ret ="CommandSetContainer " + _container + " " + _nodeName;
3855 bool CommandSetContainer::localExecute()
3857 DEBTRACE("CommandSetContainer::localExecute");
3860 Proc* proc = GuiContext::getCurrent()->getProc();
3861 if (proc->containerMap.count(_container))
3863 Container *cont = proc->containerMap[_container];
3864 Node* node = proc->getChildByName(_nodeName);
3865 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3867 Container* oldcont = pyNode->getContainer();
3869 _oldcont = pyNode->getContainer()->getName();
3870 pyNode->setContainer(cont);
3871 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3872 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3873 snode->update(ASSOCIATE, 0, subcont);
3878 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3883 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
3886 catch (Exception& ex)
3888 DEBTRACE("CommandSetContainer::localExecute() : " << ex.what());
3894 bool CommandSetContainer::localReverse()
3896 DEBTRACE("CommandSetContainer::localReverse");
3899 if (_oldcont == _container) return true;
3900 Proc* proc = GuiContext::getCurrent()->getProc();
3901 if (proc->containerMap.count(_oldcont))
3903 Container *cont = proc->containerMap[_oldcont];
3904 Node* node = proc->getChildByName(_nodeName);
3905 if (YACS::ENGINE::InlineNode* pyNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
3907 pyNode->setContainer(cont);
3908 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[pyNode];
3909 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3910 snode->update(ASSOCIATE, 0, subcont);
3915 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
3920 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
3923 catch (Exception& ex)
3925 DEBTRACE("CommandSetContainer::localReverse() : " << ex.what());
3934 // ----------------------------------------------------------------------------
3936 CommandAssociateComponentToContainer::CommandAssociateComponentToContainer(std::string instanceName,
3937 std::string container)
3938 : Command(), _container(container),_instanceName(instanceName)
3940 DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer " << instanceName << " " << container);
3941 _oldcont = "DefaultContainer";
3944 std::string CommandAssociateComponentToContainer::dump()
3946 string ret ="CommandAssociateComponentToContainer " + _container + " " + _instanceName;
3950 bool CommandAssociateComponentToContainer::localExecute()
3952 DEBTRACE("CommandAssociateComponentToContainer::localExecute");
3955 Proc* proc = GuiContext::getCurrent()->getProc();
3956 if (proc->containerMap.count(_container))
3958 Container *cont = proc->containerMap[_container];
3959 if (proc->componentInstanceMap.count(_instanceName))
3961 DEBTRACE(_instanceName);
3962 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
3963 if (compo->getContainer())
3964 _oldcont = compo->getContainer()->getName();
3965 compo->setContainer(cont);
3967 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
3968 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
3969 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
3970 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
3971 scomp->addSubjectReference(subcont);
3972 if (scomp->_subRefContainer)
3973 subcont->moveComponent(scomp->_subRefContainer);
3975 scomp->_subRefContainer = subcont->attachComponent(scomp);
3976 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
3980 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
3983 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
3986 catch (Exception& ex)
3988 DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
3994 bool CommandAssociateComponentToContainer::localReverse()
3996 DEBTRACE("CommandAssociateComponentToContainer::localReverse");
3999 if (_oldcont == _container) return true;
4000 Proc* proc = GuiContext::getCurrent()->getProc();
4001 if (proc->containerMap.count(_oldcont))
4003 Container *cont = proc->containerMap[_oldcont];
4004 if (proc->componentInstanceMap.count(_instanceName))
4006 DEBTRACE(_instanceName);
4007 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4008 compo->setContainer(cont);
4010 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4011 SubjectComponent *scomp = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4012 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4013 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4014 scomp->addSubjectReference(subcont);
4015 if (scomp->_subRefContainer)
4016 subcont->moveComponent(scomp->_subRefContainer);
4018 scomp->_subRefContainer = subcont->attachComponent(scomp);
4019 scomp->notifyServicesChange(ASSOCIATE, CONTAINER, subcont);
4023 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4026 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _oldcont;
4029 catch (Exception& ex)
4031 DEBTRACE("CommandAssociateComponentToContainer::localReverse() : " << ex.what());
4038 // ----------------------------------------------------------------------------
4040 CommandAssociateServiceToComponent::CommandAssociateServiceToComponent(std::string service,
4041 std::string instanceName)
4042 : Command(), _service(service), _instanceName(instanceName)
4044 DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "<< service << " " <<instanceName);
4048 std::string CommandAssociateServiceToComponent::dump()
4050 string ret ="CommandAssociateServiceToComponent " + _service + " " + _instanceName;
4054 bool CommandAssociateServiceToComponent::localExecute()
4056 DEBTRACE("CommandAssociateServiceToComponent::localExecute");
4059 Proc* proc = GuiContext::getCurrent()->getProc();
4060 if (_service == proc->getName()) return false; // proc is not an elementary node
4061 Node* node = proc->getChildByName(_service);
4062 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4064 if (proc->componentInstanceMap.count(_instanceName))
4066 DEBTRACE(_instanceName);
4067 ComponentInstance *compo = proc->componentInstanceMap[_instanceName];
4068 service->setComponent(compo);
4070 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4071 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4072 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4074 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4075 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4076 snode->addSubjectReference(subCompo);
4077 if (ssnode->_subRefComponent)
4079 SubjectComponent* oldcomp = dynamic_cast<SubjectComponent*>(ssnode->_subRefComponent->getParent());
4081 _oldInstance = oldcomp->getName();
4082 _oldcont = oldcomp->getComponent()->getContainer()->getName();
4083 subCompo->moveService(ssnode->_subRefComponent);
4086 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4091 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _instanceName;
4094 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4097 catch (Exception& ex)
4099 DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
4105 bool CommandAssociateServiceToComponent::localReverse()
4107 DEBTRACE("CommandAssociateServiceToComponent::localReverse");
4110 Proc* proc = GuiContext::getCurrent()->getProc();
4111 if (_service == proc->getName()) return false; // proc is not an elementary node
4112 Node* node = proc->getChildByName(_service);
4113 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
4115 ComponentInstance *compo;
4116 if (!proc->componentInstanceMap.count(_oldInstance))
4118 //component instance does not exist anymore recreate it
4119 ComponentInstance *oldcompo = service->getComponent();
4120 compo = oldcompo->clone();
4121 compo->setName(_oldInstance);
4122 proc->addComponentInstance(compo, _oldInstance);
4123 Container *cont = proc->containerMap[_oldcont];
4124 compo->setContainer(cont);
4125 SubjectProc *sproc = GuiContext::getCurrent()->getSubjectProc();
4126 sproc->addSubjectComponent(compo);
4130 compo = proc->componentInstanceMap[_oldInstance];
4133 DEBTRACE(_oldInstance);
4134 service->setComponent(compo);
4136 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(service));
4137 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[service];
4138 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4140 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4141 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4142 snode->addSubjectReference(subCompo);
4143 if (ssnode->_subRefComponent)
4144 subCompo->moveService(ssnode->_subRefComponent);
4146 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4151 GuiContext::getCurrent()->_lastErrorMessage = "Node is not a service node: " + _service;
4154 catch (Exception& ex)
4156 DEBTRACE("CommandAssociateServiceToComponent::localReverse() : " << ex.what());
4162 // ----------------------------------------------------------------------------
4164 CommandAddComponentFromCatalog::CommandAddComponentFromCatalog(YACS::ENGINE::Catalog* catalog,
4165 std::string position,
4167 std::string service)
4168 : Command(), _catalog(catalog), _position(position), _compo(compo), _service(service)
4170 DEBTRACE("CommandAddComponentFromCatalog::CommandAddComponentFromCatalog " << position << " " << compo << " " << service);
4172 _createdInstance = false;
4175 std::string CommandAddComponentFromCatalog::dump()
4177 string ret = "CommandAddComponentFromCatalog " + _position + " " + _compo + " " + _service;
4181 bool CommandAddComponentFromCatalog::localExecute()
4183 DEBTRACE("CommandAddComponentFromCatalog::localExecute");
4186 DEBTRACE("_nameInProc: " << _nameInProc);
4187 Proc* proc = GuiContext::getCurrent()->getProc();
4189 if (!_position.empty()) node = proc->getChildByName(_position);
4190 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4191 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4192 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4194 if (_catalog->_componentMap.count(_compo))
4196 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compo];
4197 if (compodef->_serviceMap.count(_service))
4199 Proc* proc = GuiContext::getCurrent()->getProc();
4200 ComponentInstance *instance =ssnode->_serviceNode->getComponent();
4202 SubjectComponent* subCompo = 0;
4203 _createdInstance = false;
4204 if(!GuiContext::getCurrent()->_mapOfSubjectComponent.count(instance))
4206 _createdInstance = true;
4207 //automatic rename of the component instance by the proc on first execute
4208 DEBTRACE("name given to proc:" << _nameInProc);
4209 proc->addComponentInstance(instance,_nameInProc, true);
4210 _nameInProc= instance->getInstanceName();
4211 DEBTRACE("name given by proc:" << _nameInProc);
4212 subCompo = GuiContext::getCurrent()->getSubjectProc()->addSubjectComponent(instance);
4215 subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[instance];
4217 ssnode->addSubjectReference(subCompo);
4218 YASSERT(! ssnode->_subRefComponent);
4219 ssnode->_subRefComponent = subCompo->attachService(ssnode);
4224 catch (Exception& ex)
4226 DEBTRACE("CommandAddComponentFromCatalog::localExecute() : " << ex.what());
4232 bool CommandAddComponentFromCatalog::localReverse()
4234 DEBTRACE("CommandAddComponentFromCatalog::localReverse");
4237 Proc* proc = GuiContext::getCurrent()->getProc();
4239 if (!_position.empty()) node = proc->getChildByName(_position);
4240 YASSERT(GuiContext::getCurrent()->_mapOfSubjectNode.count(node));
4241 SubjectNode* snode = GuiContext::getCurrent()->_mapOfSubjectNode[node];
4242 SubjectServiceNode *ssnode = dynamic_cast<SubjectServiceNode*>(snode);
4245 DEBTRACE("_nameInProc: " << _nameInProc);
4246 YASSERT(proc->componentInstanceMap.count(_nameInProc));
4247 ComponentInstance *compo = proc->componentInstanceMap[_nameInProc];
4248 YASSERT(GuiContext::getCurrent()->_mapOfSubjectComponent.count(compo));
4249 SubjectComponent *subCompo = GuiContext::getCurrent()->_mapOfSubjectComponent[compo];
4251 subCompo->detachService(ssnode);
4252 if (subCompo->hasServices())
4253 throw YACS::Exception("Component instance with services attached, not removed");
4254 Container *cont = compo->getContainer();
4255 YASSERT(GuiContext::getCurrent()->_mapOfSubjectContainer.count(cont));
4256 SubjectContainer *subcont = GuiContext::getCurrent()->_mapOfSubjectContainer[cont];
4257 subcont->detachComponent(subCompo);
4258 //remove componentInstance from proc, from context
4259 if (_createdInstance)
4261 GuiContext::getCurrent()->_mapOfSubjectComponent.erase(compo);
4262 proc->removeComponentInstance(compo);
4264 DEBTRACE("_nameInProc: " << _nameInProc);
4267 catch (Exception& ex)
4269 DEBTRACE("CommandAddComponentFromCatalog::localReverse() : " << ex.what());