+void GuiEditor::PutSubjectInBloc()
+{
+ Subject *sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
+ if (!sub)
+ {
+ Message mess("GuiEditor::PutSubjectInBloc : invalid selection!");
+ return;
+ }
+ if (SubjectNode *snode = dynamic_cast<SubjectNode*>(sub))
+ {
+ //Build the set of children node names
+ Node* node=snode->getNode();
+ ComposedNode* father=node->getFather();
+ std::list<Node*> children = father->edGetDirectDescendants();
+ std::set<std::string> names;
+ for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+ names.insert((*it)->getName());
+
+ std::stringstream tryname;
+ long newid=0;
+ while (newid < 100000)
+ {
+ tryname.str("");
+ tryname << "Bloc" << newid;
+ if(names.find(tryname.str()) == names.end())break;
+ newid++;
+ }
+
+ if (!snode->putInComposedNode(tryname.str(),"Bloc"))
+ Message mess;
+
+ return;
+ }
+ Message mess("Put in Bloc not possible for this kind of object");
+}
+
+void GuiEditor::PutGraphInNode(std::string typeNode)
+{
+ // put graph in Bloc node before
+ std::string blocname = PutGraphInBloc();
+ // put the built bloc into target node type
+ Proc* proc = GuiContext::getCurrent()->getProc();
+ Node* bloc = proc->getChildByShortName(blocname);
+ SubjectNode * sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
+ // create a target node
+ SubjectNode * snode = CreateNode(typeNode);
+ // put the built bloc into target node
+ sbloc->putInComposedNode(snode->getName(), typeNode);
+ // select a target node
+ 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->edGetDirectDescendants();
+
+ //get the set of children node names
+ std::set<std::string> names;
+ for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+ names.insert((*it)->getName());
+
+ //get the next numbered name
+ std::stringstream tryname;
+ long newid = GuiContext::getCurrent()->getNewId();
+ while (newid < 100000)
+ {
+ tryname.str("");
+ tryname << "Bloc" << newid;
+ if(names.find(tryname.str()) == names.end())break;
+ newid++;
+ }
+ std::string blocname = tryname.str();
+
+ //put one by one the child nodes of Proc node into a new Bloc node
+ std::map< std::string, std::pair<QPointF, QPointF> > aMapOfNodePosition;
+ SceneItem *item = 0;
+ SceneNodeItem *inode = 0;
+ SubjectNode * snode = 0;
+ for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+ {
+ snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
+ snode->saveLinks();
+ item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
+ YASSERT(item);
+ inode = dynamic_cast<SceneNodeItem*>(item);
+ YASSERT(inode);
+ // save current node position to restore it after reparenting
+ aMapOfNodePosition[snode->getName()] = std::make_pair(inode->pos(), QPointF(inode->getExpandedX(), inode->getExpandedY()));
+ // put in Bloc node
+ snode->putInComposedNode(blocname, "Bloc", false);
+ }
+ for (std::list<Node*>::iterator it = children.begin(); it != children.end(); ++it)
+ {
+ snode = 0;
+ snode = GuiContext::getCurrent()->_mapOfSubjectNode[(*it)];
+ snode->restoreLinks();
+ item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[snode];
+ YASSERT(item);
+ inode = dynamic_cast<SceneNodeItem*>(item);
+ YASSERT(inode);
+ // restore node position
+ inode->setPos(aMapOfNodePosition[snode->getName()].first);
+ // update node position for shrink/expand operation
+ inode->setExpandedPos(aMapOfNodePosition[snode->getName()].second);
+ // notify node about position changing
+ inode->checkGeometryChange();
+ }
+ Node* bloc = proc->getChildByShortName(blocname);
+ SubjectNode* sbloc = GuiContext::getCurrent()->_mapOfSubjectNode[bloc];
+ item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sbloc];
+ YASSERT(item);
+ // notify bloc about child position changing
+ item->checkGeometryChange();
+ // select a target bloc
+ YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
+ QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
+ return blocname;
+}
+