Salome HOME
1) Fix problem that new node does not have the usual ports ("nbBranches", evalSample...
authorakl <akl@opencascade.com>
Thu, 16 May 2013 10:58:51 +0000 (10:58 +0000)
committerakl <akl@opencascade.com>
Thu, 16 May 2013 10:58:51 +0000 (10:58 +0000)
2) Possibility to put the graph in "for loop", "while loop" and "bloc" nodes was added.

src/genericgui/GenericGui.cxx
src/genericgui/GenericGui.hxx
src/genericgui/GuiEditor.cxx
src/genericgui/GuiEditor.hxx
src/genericgui/Menus.cxx

index 7f3c12e5848923bff8788b5821ab35ce26025d77..a6bbb20402dd7faa748121dd53d5a9d2e2938df7 100644 (file)
@@ -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()
index 16390dcc862e1460303a8932dd5e675fda715525..19be69da38456c67049b78fb10a79fafcd49bff1 100644 (file)
@@ -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();
index 40074a8c0dda71567b9add7150b27820e316fdd3..24647af98495fb8e88f5990810f03729323348bf 100644 (file)
@@ -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<int, SubjectNode*>::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<SubjectBloc*>(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<SubjectBloc*>(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<Node *> children = proc->getChildren();
+  std::list<Node *> children = proc->edGetDirectDescendants();
 
   //get the set of children node names
   std::set<std::string> 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<Node*>::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;
 }
 
index dc465671eceeec94736208b228213b95289cfbc1..afcf0fa332d291a98bf1da82c096b2ab2ac824a4 100644 (file)
@@ -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,
index 42c49bb3fc4152ae801c48c812975604ad9bcda2..5121e15bf72693d715ecbd751fc73af92adf343e 100644 (file)
@@ -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<std::string, TypeCode*>::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();