3 #include "commandsProc.hxx"
6 #include "ComposedNode.hxx"
9 #include "ElementaryNode.hxx"
10 #include "InlineNode.hxx"
11 #include "ServiceNode.hxx"
12 #include "PythonNode.hxx"
13 #include "CORBANode.hxx"
14 #include "CppNode.hxx"
15 #include "XMLNode.hxx"
16 #include "SalomePythonNode.hxx"
17 #include "XMLNode.hxx"
18 #include "ForLoop.hxx"
19 #include "ForEachLoop.hxx"
20 #include "WhileLoop.hxx"
22 #include "OptimizerLoop.hxx"
23 #include "PresetNode.hxx"
24 #include "OutNode.hxx"
25 #include "StudyNodes.hxx"
26 #include "Exception.hxx"
27 #include "DataPort.hxx"
28 #include "InputDataStreamPort.hxx"
29 #include "OutputDataStreamPort.hxx"
30 #include "ComponentDefinition.hxx"
31 #include "SalomeContainer.hxx"
32 #include "SalomeComponent.hxx"
33 #include "TypeCode.hxx"
35 #include "guiContext.hxx"
41 #include "YacsTrace.hxx"
46 using namespace YACS::ENGINE;
47 using namespace YACS::HMI;
49 std::map<int, std::string> ProcInvoc::_typeNameMap;
51 // ----------------------------------------------------------------------------
53 ProcInvoc::ProcInvoc()
57 _typeNameMap[SALOMEPROC] = "SALOMEPROC";
58 _typeNameMap[BLOC] = "BLOC";
59 _typeNameMap[FOREACHLOOP] = "FOREACHLOOP";
60 _typeNameMap[OPTIMIZERLOOP] = "OPTIMIZERLOOP";
61 _typeNameMap[FORLOOP] = "FORLOOP";
62 _typeNameMap[WHILELOOP] = "WHILELOOP";
63 _typeNameMap[SWITCH] = "SWITCH";
64 _typeNameMap[PYTHONNODE] = "PYTHONNODE";
65 _typeNameMap[PYFUNCNODE] = "PYFUNCNODE";
66 _typeNameMap[CORBANODE] = "CORBANODE";
67 _typeNameMap[SALOMENODE] = "SALOMENODE";
68 _typeNameMap[CPPNODE] = "CPPNODE";
69 _typeNameMap[SALOMEPYTHONNODE] = "SALOMEPYTHONNODE";
70 _typeNameMap[XMLNODE] = "XMLNODE";
71 _typeNameMap[SPLITTERNODE] = "SPLITTERNODE";
72 _typeNameMap[DFTODSFORLOOPNODE] = "DFTODSFORLOOPNODE";
73 _typeNameMap[DSTODFFORLOOPNODE] = "DSTODFFORLOOPNODE";
74 _typeNameMap[PRESETNODE] = "PRESETNODE";
75 _typeNameMap[OUTNODE] = "OUTNODE";
76 _typeNameMap[STUDYINNODE] = "STUDYINNODE";
77 _typeNameMap[STUDYOUTNODE] = "STUDYOUTNODE";
78 _typeNameMap[INPUTPORT] = "INPUTPORT";
79 _typeNameMap[OUTPUTPORT] = "OUTPUTPORT";
80 _typeNameMap[INPUTDATASTREAMPORT] = "INPUTDATASTREAMPORT";
81 _typeNameMap[OUTPUTDATASTREAMPORT] = "OUTPUTDATASTREAMPORT";
82 _typeNameMap[CONTAINER] = "CONTAINER";
83 _typeNameMap[COMPONENT] = "COMPONENT";
84 _typeNameMap[REFERENCE] = "REFERENCE";
85 _typeNameMap[DATATYPE] = "DATATYPE";
88 TypeOfElem ProcInvoc::getTypeOfNode(YACS::ENGINE::Node* node)
90 TypeOfElem nodeType = UNKNOWN;
91 if (dynamic_cast<YACS::ENGINE::Bloc*>(node)) nodeType = BLOC;
92 else if (dynamic_cast<YACS::ENGINE::PythonNode*>(node)) nodeType = PYTHONNODE;
93 else if (dynamic_cast<YACS::ENGINE::PyFuncNode*>(node)) nodeType = PYFUNCNODE;
94 else if (dynamic_cast<YACS::ENGINE::CORBANode*>(node)) nodeType = CORBANODE;
95 else if (dynamic_cast<YACS::ENGINE::CppNode*>(node)) nodeType = CPPNODE;
96 else if (dynamic_cast<YACS::ENGINE::SalomeNode*>(node)) nodeType = SALOMENODE;
97 else if (dynamic_cast<YACS::ENGINE::SalomePythonNode*>(node)) nodeType = SALOMEPYTHONNODE;
98 else if (dynamic_cast<YACS::ENGINE::XmlNode*>(node)) nodeType = XMLNODE;
99 else if (dynamic_cast<YACS::ENGINE::SplitterNode*>(node)) nodeType = SPLITTERNODE;
100 else if (dynamic_cast<YACS::ENGINE::ForLoop*>(node)) nodeType = FORLOOP;
101 else if (dynamic_cast<YACS::ENGINE::WhileLoop*>(node)) nodeType = WHILELOOP;
102 else if (dynamic_cast<YACS::ENGINE::Switch*>(node)) nodeType = SWITCH;
103 else if (dynamic_cast<YACS::ENGINE::ForEachLoop*>(node)) nodeType = FOREACHLOOP;
104 else if (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(node)) nodeType = OPTIMIZERLOOP;
105 else if (dynamic_cast<YACS::ENGINE::PresetNode*>(node)) nodeType = PRESETNODE;
106 else if (dynamic_cast<YACS::ENGINE::OutNode*>(node)) nodeType = OUTNODE;
107 else if (dynamic_cast<YACS::ENGINE::StudyInNode*>(node)) nodeType = STUDYINNODE;
108 else if (dynamic_cast<YACS::ENGINE::StudyOutNode*>(node)) nodeType = STUDYOUTNODE;
112 TypeOfElem ProcInvoc::getTypeOfPort(YACS::ENGINE::DataPort* port)
114 TypeOfElem portType = UNKNOWN;
115 if (dynamic_cast<YACS::ENGINE::InputPort*>(port)) portType = INPUTPORT;
116 else if (dynamic_cast<YACS::ENGINE::OutputPort*>(port)) portType = OUTPUTPORT;
117 else if (dynamic_cast<YACS::ENGINE::InputDataStreamPort*>(port)) portType = INPUTDATASTREAMPORT;
118 else if (dynamic_cast<YACS::ENGINE::OutputDataStreamPort*>(port)) portType = OUTPUTDATASTREAMPORT;
122 std::string ProcInvoc::getTypeName(TypeOfElem type)
124 if (_typeNameMap.count(type))
125 return _typeNameMap[type];
130 // ----------------------------------------------------------------------------
132 CommandAddNodeFromCatalog::CommandAddNodeFromCatalog(YACS::ENGINE::Catalog *catalog,
135 std::string position,
138 : Command(), _catalog(catalog), _compoName(compo), _typeName(type),
139 _position(position), _name(name), _swCase(swCase)
142 if (_compoName.empty())
144 if (_catalog->_nodeMap.count(_typeName))
145 _nodeToClone = _catalog->_nodeMap[_typeName];
146 else if (_catalog->_composednodeMap.count(_typeName))
147 _nodeToClone = _catalog->_composednodeMap[_typeName];
150 if (_catalog->_componentMap.count(_compoName))
152 YACS::ENGINE::ComponentDefinition* compodef = _catalog->_componentMap[_compoName];
153 if (compodef->_serviceMap.count(_typeName))
154 _nodeToClone = compodef->_serviceMap[_typeName];
157 _typeNode = ProcInvoc::getTypeOfNode(_nodeToClone);
161 YACS::ENGINE::Node *CommandAddNodeFromCatalog::getNode()
166 bool CommandAddNodeFromCatalog::localExecute()
171 Proc* proc = GuiContext::getCurrent()->getProc();
173 if (!_position.empty()) node = proc->getChildByName(_position);
174 ComposedNode* father =dynamic_cast<ComposedNode*> (node);
177 son = _nodeToClone->clone(0);
182 TypeOfElem fatherType = ProcInvoc::getTypeOfNode(father);
186 (dynamic_cast<YACS::ENGINE::Bloc*>(father))->edAddChild(son);
189 (dynamic_cast<YACS::ENGINE::ForLoop*>(father))->edSetNode(son);
192 (dynamic_cast<YACS::ENGINE::WhileLoop*>(father))->edSetNode(son);
195 (dynamic_cast<YACS::ENGINE::Switch*>(father))->edSetNode(_swCase,son);
198 (dynamic_cast<YACS::ENGINE::ForEachLoop*>(father))->edSetNode(son);
201 (dynamic_cast<YACS::ENGINE::OptimizerLoop*>(father))->edSetNode(son);
209 catch (Exception& ex)
211 DEBTRACE("CommandAddNode::localExecute() : " << ex.what());
212 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
219 bool CommandAddNodeFromCatalog::localReverse()
223 // ----------------------------------------------------------------------------
225 CommandRenameNode::CommandRenameNode(std::string position, std::string name)
226 : Command(), _position(position), _name(name)
228 DEBTRACE("CommandRenameNode::CommandRenameNode " << _position << " " << _name);
231 bool CommandRenameNode::localExecute()
233 Proc* proc = GuiContext::getCurrent()->getProc();
237 if (_position != proc->getName()) node = proc->getChildByName(_position);
238 node->setName(_name);
240 catch (Exception& ex)
242 DEBTRACE("CommandRenameNode::localExecute() : " << ex.what());
243 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
249 bool CommandRenameNode::localReverse()
253 // ----------------------------------------------------------------------------
255 CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog(YACS::ENGINE::Catalog* catalog,
256 std::string typeName)
257 : Command(), _catalog(catalog), _typeName(typeName)
259 DEBTRACE("CommandAddDataTypeFromCatalog::CommandAddDataTypeFromCatalog: " << typeName);
262 YACS::ENGINE::TypeCode *CommandAddDataTypeFromCatalog::getTypeCode()
265 if (GuiContext::getCurrent()->getProc()->typeMap.count(_typeName))
266 return GuiContext::getCurrent()->getProc()->typeMap[_typeName];
270 bool CommandAddDataTypeFromCatalog::localExecute()
272 Proc* proc = GuiContext::getCurrent()->getProc();
273 if (proc->typeMap.count(_typeName))
275 DEBTRACE("typecode already existing in proc: " << _typeName);
276 //GuiContext::getCurrent()->_lastErrorMessage = "typecode already existing in proc: " + _typeName;
281 if (_catalog->_typeMap.count(_typeName))
283 DEBTRACE("typecode found in catalog, cloned: " << _typeName);
284 proc->typeMap[_typeName] = _catalog->_typeMap[_typeName]->clone();
287 GuiContext::getCurrent()->_lastErrorMessage = "typecode not found in catalog: " + _typeName;
291 bool CommandAddDataTypeFromCatalog::localReverse()
296 // ----------------------------------------------------------------------------
298 CommandAddInputPortFromCatalog::CommandAddInputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
302 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
307 YACS::ENGINE::InputPort *CommandAddInputPortFromCatalog::getInputPort()
312 bool CommandAddInputPortFromCatalog::localExecute()
317 Proc* proc = GuiContext::getCurrent()->getProc();
318 Node* node = proc->getChildByName(_node);
319 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
322 if (_catalog->_typeMap.count(_typePort))
323 son = father->edAddInputPort(_name, _catalog->_typeMap[_typePort]);
326 DEBTRACE(_typePort << " not found in catalog");
327 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
332 catch (Exception& ex)
334 DEBTRACE("CommandAddInputPortFromCatalog::localExecute() : " << ex.what());
335 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
339 return (_inputPort != 0);
342 bool CommandAddInputPortFromCatalog::localReverse()
346 // ----------------------------------------------------------------------------
348 CommandAddOutputPortFromCatalog::CommandAddOutputPortFromCatalog(YACS::ENGINE::Catalog *catalog,
352 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
357 YACS::ENGINE::OutputPort *CommandAddOutputPortFromCatalog::getOutputPort()
362 bool CommandAddOutputPortFromCatalog::localExecute()
367 Proc* proc = GuiContext::getCurrent()->getProc();
368 Node* node = proc->getChildByName(_node);
369 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
372 if (_catalog->_typeMap.count(_typePort))
373 son = father->edAddOutputPort(_name, _catalog->_typeMap[_typePort]);
376 DEBTRACE(_typePort << " not found in catalog");
377 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
382 catch (Exception& ex)
384 DEBTRACE("CommandAddOutputPortFromCatalog::localExecute() : " << ex.what());
385 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
389 return (_outputPort != 0);
392 bool CommandAddOutputPortFromCatalog::localReverse()
396 // ----------------------------------------------------------------------------
398 CommandAddIDSPortFromCatalog::CommandAddIDSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
402 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
407 YACS::ENGINE::InputDataStreamPort *CommandAddIDSPortFromCatalog::getIDSPort()
412 bool CommandAddIDSPortFromCatalog::localExecute()
414 InputDataStreamPort *son = 0;
417 Proc* proc = GuiContext::getCurrent()->getProc();
418 Node* node = proc->getChildByName(_node);
419 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
422 if (_catalog->_typeMap.count(_typePort))
423 son = father->edAddInputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
426 DEBTRACE(_typePort << " not found in catalog");
427 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
432 catch (Exception& ex)
434 DEBTRACE("CommandAddIDSPortFromCatalog::localExecute() : " << ex.what());
435 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
439 return (_IDSPort != 0);
442 bool CommandAddIDSPortFromCatalog::localReverse()
446 // ----------------------------------------------------------------------------
448 CommandAddODSPortFromCatalog::CommandAddODSPortFromCatalog(YACS::ENGINE::Catalog *catalog,
452 : Command(), _catalog(catalog), _typePort(type), _node(node), _name(name)
457 YACS::ENGINE::OutputDataStreamPort *CommandAddODSPortFromCatalog::getODSPort()
462 bool CommandAddODSPortFromCatalog::localExecute()
464 OutputDataStreamPort *son = 0;
467 Proc* proc = GuiContext::getCurrent()->getProc();
468 Node* node = proc->getChildByName(_node);
469 ElementaryNode* father =dynamic_cast<ElementaryNode*> (node);
472 if (_catalog->_typeMap.count(_typePort))
473 son = father->edAddOutputDataStreamPort(_name, _catalog->_typeMap[_typePort]);
476 DEBTRACE(_typePort << " not found in catalog");
477 GuiContext::getCurrent()->_lastErrorMessage = _typePort + " not found in catalog";
482 catch (Exception& ex)
484 DEBTRACE("CommandAddODSPortFromCatalog::localExecute() : " << ex.what());
485 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
489 return (_ODSPort != 0);
492 bool CommandAddODSPortFromCatalog::localReverse()
496 // ----------------------------------------------------------------------------
498 CommandDestroy::CommandDestroy(std::string position, Subject* subject)
499 : Command(), _position(position), _subject(subject)
501 DEBTRACE("CommandDestroy::CommandDestroy");
502 //todo: store what is needed to recreate the subject
505 bool CommandDestroy::localExecute()
507 DEBTRACE("CommandDestroy::localExecute");
510 Subject::erase(_subject);
514 catch (Exception& ex)
516 DEBTRACE("CommandDestroy::localExecute() : " << ex.what());
517 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
522 bool CommandDestroy::localReverse()
526 // ----------------------------------------------------------------------------
528 CommandAddLink::CommandAddLink(std::string outNode, std::string outPort,
529 std::string inNode, std::string inPort)
530 : Command(), _outNode(outNode), _outPort(outPort), _inNode(inNode), _inPort(inPort)
532 DEBTRACE("CommandAddLink::CommandAddLink "<<outNode<<"."<<outPort<<"->"<<inNode<<"."<<inPort);
535 bool CommandAddLink::localExecute()
537 DEBTRACE(_outNode<<"."<<_outPort<<"->"<<_inNode<<"."<<_inPort);
540 Proc* proc = GuiContext::getCurrent()->getProc();
541 Node* outn = proc->getChildByName(_outNode);
542 Node* inn = proc->getChildByName(_inNode);
543 OutPort* outp = outn->getOutPort(_outPort);
544 InPort* inp = inn->getInPort(_inPort);
545 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn->getFather(),inn->getFather());
546 DEBTRACE(cla->getName());
547 if (dynamic_cast<OutputDataStreamPort*>(outp))
548 cla->edAddLink(outp,inp);
550 cla->edAddDFLink(outp,inp);
553 catch (Exception& ex)
555 DEBTRACE("CommandAddLink::localExecute() : " << ex.what());
556 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
561 bool CommandAddLink::localReverse()
565 // ----------------------------------------------------------------------------
567 CommandAddControlLink::CommandAddControlLink(std::string outNode, std::string inNode)
568 : Command(), _outNode(outNode), _inNode(inNode)
570 DEBTRACE("CommandAddControlLink::CommandAddControlLink "<<outNode<<"-->>"<<inNode);
573 bool CommandAddControlLink::localExecute()
577 Proc* proc = GuiContext::getCurrent()->getProc();
579 if (! _outNode.empty())
580 outn = proc->getChildByName(_outNode);
582 if (! _inNode.empty())
583 inn = proc->getChildByName(_inNode);
584 ComposedNode *cla = ComposedNode::getLowestCommonAncestor(outn,inn);
585 DEBTRACE(cla->getName());
586 cla->edAddCFLink(outn,inn);
589 catch (Exception& ex)
591 DEBTRACE("CommandAddControlLink::localExecute() : " << ex.what());
592 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
597 bool CommandAddControlLink::localReverse()
601 // ----------------------------------------------------------------------------
603 CommandAddContainer::CommandAddContainer(std::string name,
604 std::string refContainer)
605 : Command(), _name(name), _containerToClone(refContainer), _container(0)
607 DEBTRACE("CommandAddContainer::CommandAddContainer " << name << " " << refContainer);
610 bool CommandAddContainer::localExecute()
614 Proc* proc = GuiContext::getCurrent()->getProc();
615 if (proc->containerMap.count(_name))
617 GuiContext::getCurrent()->_lastErrorMessage = "There is already a container with that name";
620 Container *container = new SalomeContainer();
621 if (! _containerToClone.empty())
623 if (proc->containerMap.count(_containerToClone))
625 Container *ref = proc->containerMap[_containerToClone];
627 container->setProperties(ref->getProperties());
631 GuiContext::getCurrent()->_lastErrorMessage = "There is no reference container to clone properties";
635 _container = container;
636 _container->setName(_name);
637 proc->containerMap[_name] = _container;
640 catch (Exception& ex)
642 DEBTRACE("CommandAddContainer::localExecute() : " << ex.what());
643 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
648 bool CommandAddContainer::localReverse()
652 YACS::ENGINE::Container* CommandAddContainer::getContainer()
657 // ----------------------------------------------------------------------------
659 CommandSetContainerProperties::CommandSetContainerProperties(std::string container,
660 std::map<std::string,std::string> properties)
661 : Command(), _container(container), _properties(properties)
663 DEBTRACE("CommandSetContainerProperties::CommandSetContainerProperties " << container);
666 bool CommandSetContainerProperties::localExecute()
670 Proc* proc = GuiContext::getCurrent()->getProc();
671 if (proc->containerMap.count(_container))
673 Container *ref = proc->containerMap[_container];
675 ref->setProperties(_properties);
678 GuiContext::getCurrent()->_lastErrorMessage = "container not found: " + _container;
681 catch (Exception& ex)
683 DEBTRACE("CommandSetContainerProperties::localExecute() : " << ex.what());
684 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
689 bool CommandSetContainerProperties::localReverse()
693 // ----------------------------------------------------------------------------
695 CommandSetDSPortProperties::CommandSetDSPortProperties(std::string node, std::string port, bool isInport,
696 std::map<std::string,std::string> properties)
697 : Command(), _nodeName(node), _portName(port), _isInport(isInport), _properties(properties)
699 DEBTRACE("CommandSetDSPortProperties::CommandSetDSPortProperties " << node << "." << port << " " << isInport);
702 bool CommandSetDSPortProperties::localExecute()
706 Proc* proc = GuiContext::getCurrent()->getProc();
707 Node* node = proc->getChildByName(_nodeName);
708 DataStreamPort* DSPort = 0;
710 DSPort = node->getInputDataStreamPort(_portName);
712 DSPort = node->getOutputDataStreamPort(_portName);
713 DSPort->setProperties(_properties);
716 catch (Exception& ex)
718 DEBTRACE("CommandSetDSPortProperties::localExecute() : " << ex.what());
719 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
724 bool CommandSetDSPortProperties::localReverse()
728 // ----------------------------------------------------------------------------
730 CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName(std::string node, std::string funcName)
731 : Command(), _nodeName(node), _funcName(funcName)
733 DEBTRACE("CommandSetFuncNodeFunctionName::CommandSetFuncNodeFunctionName " << node << " " <<funcName);
736 bool CommandSetFuncNodeFunctionName::localExecute()
740 Proc* proc = GuiContext::getCurrent()->getProc();
741 Node* node = proc->getChildByName(_nodeName);
742 if (_funcName.empty())
744 GuiContext::getCurrent()->_lastErrorMessage = "InlineFuncNode function name empty: " + _nodeName;
747 if (YACS::ENGINE::InlineFuncNode* funcNode = dynamic_cast<YACS::ENGINE::InlineFuncNode*>(node))
749 funcNode->setFname(_funcName);
754 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineFuncNode: " + _nodeName;
758 catch (Exception& ex)
760 DEBTRACE("CommandSetFuncNodeFunctionName::localExecute() : " << ex.what());
761 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
766 bool CommandSetFuncNodeFunctionName::localReverse()
770 // ----------------------------------------------------------------------------
772 CommandSetInlineNodeScript::CommandSetInlineNodeScript(std::string node, std::string script)
773 : Command(), _nodeName(node), _script(script)
775 DEBTRACE("CommandSetInlineNodeScript::CommandSetInlineNodeScript " << node << " " <<script);
778 bool CommandSetInlineNodeScript::localExecute()
782 Proc* proc = GuiContext::getCurrent()->getProc();
783 Node* node = proc->getChildByName(_nodeName);
786 GuiContext::getCurrent()->_lastErrorMessage = "InlineNode script empty: " + _nodeName;
789 if (YACS::ENGINE::InlineNode* inlineNode = dynamic_cast<YACS::ENGINE::InlineNode*>(node))
791 inlineNode->setScript(_script);
796 GuiContext::getCurrent()->_lastErrorMessage = "node is not an InlineNode: " + _nodeName;
800 catch (Exception& ex)
802 DEBTRACE("CommandSetInlineNodeScript::localExecute() : " << ex.what());
803 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
808 bool CommandSetInlineNodeScript::localReverse()
812 // ----------------------------------------------------------------------------
814 CommandAddComponentInstance::CommandAddComponentInstance(std::string compoName)
815 : Command(), _compoName(compoName), _compoInst(0)
817 DEBTRACE("CommandAddComponentInstance::CommandAddComponentInstance " <<_compoName);
820 bool CommandAddComponentInstance::localExecute()
824 Proc* proc = GuiContext::getCurrent()->getProc();
825 _compoInst = new SalomeComponent(_compoName);
826 pair<string,int> key = pair<string,int>(_compoName, _compoInst->getNumId());
827 proc->componentInstanceMap[key] = _compoInst;
830 catch (Exception& ex)
832 DEBTRACE("CommandAddComponentInstance::localExecute() : " << ex.what());
833 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
838 bool CommandAddComponentInstance::localReverse()
842 YACS::ENGINE::ComponentInstance* CommandAddComponentInstance::getComponentInstance()
848 // ----------------------------------------------------------------------------
850 CommandAssociateComponentToContainer::CommandAssociateComponentToContainer(std::pair<std::string,int> key,
851 std::string container)
852 : Command(), _key(key), _container(container)
854 DEBTRACE("CommandAssociateComponentToContainer::CommandAssociateComponentToContainer "
855 << key.first << " " << key.second << " " << container);
858 bool CommandAssociateComponentToContainer::localExecute()
862 Proc* proc = GuiContext::getCurrent()->getProc();
863 if (proc->containerMap.count(_container))
865 Container *cont = proc->containerMap[_container];
866 if (proc->componentInstanceMap.count(_key))
868 ComponentInstance *compo = proc->componentInstanceMap[_key];
869 compo->setContainer(cont);
873 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _key.first;
876 GuiContext::getCurrent()->_lastErrorMessage = "Container not found: " + _container;
879 catch (Exception& ex)
881 DEBTRACE("CommandAssociateComponentToContainer::localExecute() : " << ex.what());
882 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
887 bool CommandAssociateComponentToContainer::localReverse()
891 // ----------------------------------------------------------------------------
893 CommandAssociateServiceToComponent::CommandAssociateServiceToComponent(std::string service,
894 std::pair<std::string,int> key)
895 : Command(), _service(service), _key(key)
897 DEBTRACE("CommandAssociateServiceToComponent::CommandAssociateServiceToComponent "
898 << service << " " << key.first << " " << key.second);
901 bool CommandAssociateServiceToComponent::localExecute()
905 Proc* proc = GuiContext::getCurrent()->getProc();
906 if (_service == proc->getName()) return false; // proc is not an elementary node
907 Node* node = proc->getChildByName(_service);
908 if (ServiceNode *service = dynamic_cast<ServiceNode*>(node))
910 if (proc->componentInstanceMap.count(_key))
912 ComponentInstance *compo = proc->componentInstanceMap[_key];
913 service->setComponent(compo);
917 GuiContext::getCurrent()->_lastErrorMessage = "Component instance not found: " + _key.first;
920 GuiContext::getCurrent()->_lastErrorMessage = "Node is note a service node: " + _service;
923 catch (Exception& ex)
925 DEBTRACE("CommandAssociateServiceToComponent::localExecute() : " << ex.what());
926 GuiContext::getCurrent()->_lastErrorMessage = ex.what();
931 bool CommandAssociateServiceToComponent::localReverse()
935 // ----------------------------------------------------------------------------