From: akl Date: Thu, 16 May 2013 10:58:51 +0000 (+0000) Subject: 1) Fix problem that new node does not have the usual ports ("nbBranches", evalSample... X-Git-Tag: V7_3_0a1~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=55205bc36f9b80c68e8474cc2837fc771a4ae07e;p=modules%2Fyacs.git 1) Fix problem that new node does not have the usual ports ("nbBranches", evalSample", ...). 2) Possibility to put the graph in "for loop", "while loop" and "bloc" nodes was added. --- diff --git a/src/genericgui/GenericGui.cxx b/src/genericgui/GenericGui.cxx index 7f3c12e58..a6bbb2040 100644 --- a/src/genericgui/GenericGui.cxx +++ b/src/genericgui/GenericGui.cxx @@ -416,9 +416,21 @@ void GenericGui::createActions() tr("Put node in block"), tr("Put node in block"), 0, _parent, false, this, SLOT(onPutInBloc())); - _putGraphInOptimizerLoopAct = _wrapper->createAction(getMenuId(), tr("Optimizer Loop"), QIcon("icons:paste.png"), - tr("Optimizer Loop"), tr("Optimizer Loop"), - 0, _parent, false, this, SLOT(onPutGraphInOptimizerLoop())); + _putGraphInBlocAct = _wrapper->createAction(getMenuId(), tr("Bloc"), QIcon("icons:new_block_node.png"), + tr("Bloc"), tr("Bloc"), + 0, _parent, false, this, SLOT(onPutGraphInBloc())); + + _putGraphInForLoopAct = _wrapper->createAction(getMenuId(), tr("For Loop"), QIcon("icons:new_for_loop_node.png"), + tr("For Loop"), tr("For Loop"), + 0, _parent, false, this, SLOT(onPutGraphInForLoop())); + + _putGraphInWhileLoopAct = _wrapper->createAction(getMenuId(), tr("While Loop"), QIcon("icons:new_while_loop_node.png"), + tr("While Loop"), tr("While Loop"), + 0, _parent, false, this, SLOT(onPutGraphInWhileLoop())); + + _putGraphInOptimizerLoopAct = _wrapper->createAction(getMenuId(), tr("Optimizer Loop"), QIcon("icons:new_for_loop_node.png"), + tr("Optimizer Loop"), tr("Optimizer Loop"), + 0, _parent, false, this, SLOT(onPutGraphInOptimizerLoop())); _arrangeLocalNodesAct = _wrapper->createAction(getMenuId(), tr("arrange nodes on that bloc level, without recursion"), QIcon("icons:arrange_nodes.png"), tr("arrange local nodes"), tr("arrange nodes on that bloc level, without recursion"), @@ -2067,16 +2079,35 @@ void GenericGui::onPutInBloc() _guiEditor->PutSubjectInBloc(); } +void GenericGui::onPutGraphInBloc() +{ + DEBTRACE("GenericGui::onPutGraphInBloc"); + _guiEditor->PutGraphInBloc(); + _guiEditor->arrangeNodes(false); +} + +void GenericGui::onPutGraphInForLoop() +{ + DEBTRACE("GenericGui::onPutGraphInForLoop"); + _guiEditor->PutGraphInNode("ForLoop"); +} + void GenericGui::putGraphInForeachLoop(std::string type) { DEBTRACE("GenericGui::PutGraphInForeachLoop"); - _guiEditor->PutGraphInForeachLoop(type); + _guiEditor->PutGraphInNode("ForEachLoop_"+type); +} + +void GenericGui::onPutGraphInWhileLoop() +{ + DEBTRACE("GenericGui::onPutGraphInWhileLoop"); + _guiEditor->PutGraphInNode("WhileLoop"); } void GenericGui::onPutGraphInOptimizerLoop() { DEBTRACE("GenericGui::onPutGraphInOptimizerLoop"); - _guiEditor->PutGraphInOptimizerLoop(); + _guiEditor->PutGraphInNode("OptimizerLoop"); } void GenericGui::onArrangeLocalNodes() diff --git a/src/genericgui/GenericGui.hxx b/src/genericgui/GenericGui.hxx index 16390dcc8..19be69da3 100644 --- a/src/genericgui/GenericGui.hxx +++ b/src/genericgui/GenericGui.hxx @@ -150,6 +150,9 @@ namespace YACS QAction *_copyItemAct; QAction *_pasteItemAct; QAction *_putInBlocAct; + QAction *_putGraphInBlocAct; + QAction *_putGraphInForLoopAct; + QAction *_putGraphInWhileLoopAct; QAction *_putGraphInOptimizerLoopAct; QAction *_arrangeLocalNodesAct; QAction *_arrangeRecurseNodesAct; @@ -286,6 +289,9 @@ namespace YACS void onCopyItem(); void onPasteItem(); void onPutInBloc(); + void onPutGraphInBloc(); + void onPutGraphInForLoop(); + void onPutGraphInWhileLoop(); void onPutGraphInOptimizerLoop(); void onArrangeLocalNodes(); void onArrangeRecurseNodes(); diff --git a/src/genericgui/GuiEditor.cxx b/src/genericgui/GuiEditor.cxx index 40074a8c0..24647af98 100644 --- a/src/genericgui/GuiEditor.cxx +++ b/src/genericgui/GuiEditor.cxx @@ -95,7 +95,7 @@ void GuiEditor::CreateNodeFromCatalog(const ItemMimeData* myData, SubjectCompose } } -void GuiEditor::CreateNode(std::string typeNode) +SubjectNode* GuiEditor::CreateNode(std::string typeNode) { DEBTRACE("GuiEditor::CreateNode " << typeNode); YACS::ENGINE::Catalog *catalog = YACS::ENGINE::getSALOMERuntime()->getBuiltinCatalog(); @@ -104,7 +104,7 @@ void GuiEditor::CreateNode(std::string typeNode) if (!sub) { DEBTRACE("GuiEditor::CreateNode : invalid selection!"); - return; + return 0; } DEBTRACE(sub->getName()); @@ -112,18 +112,20 @@ void GuiEditor::CreateNode(std::string typeNode) if (!cnode) { DEBTRACE("GuiEditor::CreateNode : no ComposedNode selected!"); - return; + return 0; } - _createNode(catalog, cnode, typeNode, "", Resource::COMPONENT_INSTANCE_NEW); + return _createNode(catalog, cnode, typeNode, "", Resource::COMPONENT_INSTANCE_NEW); } -void GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog, - SubjectComposedNode *cnode, - std::string service, - std::string compoName, - bool createNewComponentInstance) +SubjectNode* GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog, + SubjectComposedNode *cnode, + std::string service, + std::string compoName, + bool createNewComponentInstance) { + SubjectNode* aNewNode = 0; + // --- find a name not used string name = service; @@ -161,7 +163,8 @@ void GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog, map::reverse_iterator rit = bodyMap.rbegin(); swCase = (*rit).first + 1; } - if (!aSwitch->addNode(catalog, compoName, service, name, createNewComponentInstance, swCase)) + aNewNode = aSwitch->addNode(catalog, compoName, service, name, createNewComponentInstance, swCase); + if (!aNewNode) Message mess; } else if (cnode && (dynamic_cast(cnode) == 0) && cnode->getChild() != 0) @@ -182,7 +185,8 @@ void GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog, { //the bloc has been successfully created. Add the new node SubjectBloc* newbloc = dynamic_cast(cnode->getChild()); - if (!newbloc->addNode(catalog, compoName, service, name, createNewComponentInstance)) + aNewNode = newbloc->addNode(catalog, compoName, service, name, createNewComponentInstance); + if (!aNewNode) Message mess; } else @@ -190,8 +194,10 @@ void GuiEditor::_createNode(YACS::ENGINE::Catalog* catalog, } } else if (cnode) - if (!cnode->addNode(catalog, compoName, service, name, createNewComponentInstance)) + aNewNode = cnode->addNode(catalog, compoName, service, name, createNewComponentInstance); + if (!aNewNode) Message mess; + return aNewNode; } void GuiEditor::AddTypeFromCatalog(const ItemMimeData* myData) @@ -533,34 +539,27 @@ void GuiEditor::PutSubjectInBloc() Message mess("Put in Bloc not possible for this kind of object"); } -void GuiEditor::PutGraphInForeachLoop(std::string typeNode) +void GuiEditor::PutGraphInNode(std::string typeNode) { // put graph in Bloc node before std::string blocname = PutGraphInBloc(); - Proc* proc = GuiContext::getCurrent()->getProc(); Node* bloc = proc->getChildByShortName(blocname); SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc]; - //put the built bloc into target node - sbloc->putInComposedNode("ForEachLoop_"+typeNode,"ForEachLoop_"+typeNode); -} - -void GuiEditor::PutGraphInOptimizerLoop() -{ - // put graph in Bloc node before - std::string blocname = PutGraphInBloc(); - - Proc* proc = GuiContext::getCurrent()->getProc(); - Node* bloc = proc->getChildByShortName(blocname); - SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc]; - //put the built bloc into target node - sbloc->putInComposedNode("OptimizerLoop0","OptimizerLoop"); + // create a target node + SubjectNode * snode = CreateNode(typeNode); + // put the built bloc into target node + sbloc->putInComposedNode(snode->getName(), typeNode); + // arrange local nodes in Proc + YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc(); + QtGuiContext::getQtCurrent()->setSelectedSubject(subproc); + arrangeNodes(false); } std::string GuiEditor::PutGraphInBloc() { Proc* proc = GuiContext::getCurrent()->getProc(); - std::list children = proc->getChildren(); + std::list children = proc->edGetDirectDescendants(); //get the set of children node names std::set names; @@ -569,7 +568,7 @@ std::string GuiEditor::PutGraphInBloc() //get the next numbered name std::stringstream tryname; - long newid=0; + long newid = GuiContext::getCurrent()->getNewId(); while (newid < 100000) { tryname.str(""); @@ -585,7 +584,7 @@ std::string GuiEditor::PutGraphInBloc() { snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)]; snode->saveLinks(); - snode->putInComposedNode(blocname,"Bloc", false); + snode->putInComposedNode(blocname, "Bloc", false); } for (std::list::iterator it = children.begin(); it != children.end(); ++it) { @@ -593,6 +592,10 @@ std::string GuiEditor::PutGraphInBloc() snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)]; snode->restoreLinks(); } + // arrange local nodes in Proc + YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc(); + QtGuiContext::getQtCurrent()->setSelectedSubject(subproc); + arrangeNodes(false); return blocname; } diff --git a/src/genericgui/GuiEditor.hxx b/src/genericgui/GuiEditor.hxx index dc465671e..afcf0fa33 100644 --- a/src/genericgui/GuiEditor.hxx +++ b/src/genericgui/GuiEditor.hxx @@ -35,6 +35,7 @@ namespace YACS namespace HMI { class Subject; + class SubjectNode; class SubjectElementaryNode; class SubjectComposedNode; class SubjectDataPort; @@ -50,7 +51,7 @@ namespace YACS SubjectComposedNode *cnode, bool createNewComponentInstance); void AddTypeFromCatalog(const ItemMimeData* myData); - void CreateNode(std::string typeNode); + SubjectNode* CreateNode(std::string typeNode); void CreateBloc(); void CreateForLoop(); void CreateForEachLoop(std::string type ); @@ -80,8 +81,7 @@ namespace YACS void PasteSubject(); void PutSubjectInBloc(); std::string PutGraphInBloc(); - void PutGraphInForeachLoop(std::string typeNode); - void PutGraphInOptimizerLoop(); + void PutGraphInNode(std::string typeNode); void shrinkExpand(); void rebuildLinks(); void arrangeNodes(bool isRecursive); @@ -91,7 +91,7 @@ namespace YACS QString asciiFilter(const QString & name); protected: - void _createNode(YACS::ENGINE::Catalog* catalog, + SubjectNode* _createNode(YACS::ENGINE::Catalog* catalog, SubjectComposedNode *cnode, std::string service, std::string compoName, diff --git a/src/genericgui/Menus.cxx b/src/genericgui/Menus.cxx index 42c49bb3f..5121e15bf 100644 --- a/src/genericgui/Menus.cxx +++ b/src/genericgui/Menus.cxx @@ -91,7 +91,7 @@ void MenusBase::buildForEachMenu(QMenu *m, QActionGroup* actgroup) QPixmap pixmap; pixmap.load("icons:new_foreach_loop_node.png"); - QMenu *ForEachMenu=m->addMenu(QIcon(pixmap),"ForEachLoop"); + QMenu *ForEachMenu=m->addMenu(QIcon(pixmap),"ForEach Loop"); Proc* proc = GuiContext::getCurrent()->getProc(); std::map::const_iterator it = proc->typeMap.begin(); @@ -250,7 +250,11 @@ void ProcMenu::popupMenu(QWidget *caller, const QPoint &globalPos, const QString menu.addAction(gmain->_pasteItemAct); QMenu *PINmenu = menu.addMenu(tr("Put Graph Content in Node")); + PINmenu->addAction(gmain->_putGraphInBlocAct); + PINmenu->addSeparator(); + PINmenu->addAction(gmain->_putGraphInForLoopAct); addForEachMenuToPutGraph(PINmenu,&actgroup2); + PINmenu->addAction(gmain->_putGraphInWhileLoopAct); PINmenu->addAction(gmain->_putGraphInOptimizerLoopAct); menu.addSeparator();