Salome HOME
Work in progress : workload manager engine test ok
[modules/yacs.git] / src / genericgui / GuiEditor.cxx
index 24647af98495fb8e88f5990810f03729323348bf..7c06ea53b7e260e235a36f678c84b7aa1a54c4cc 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2019  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -269,7 +269,7 @@ void GuiEditor::CreateContainer()
   DEBTRACE("GuiEditor::CreateContainer");
   SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
   YASSERT(sproc);
-  SubjectContainer *scont = 0;
+  SubjectContainerBase *scont = 0;
   while (!scont)
     {
       std::stringstream name;
@@ -281,6 +281,23 @@ void GuiEditor::CreateContainer()
     }
 }
 
+void GuiEditor::CreateHPContainer()
+{
+  DEBTRACE("GuiEditor::CreateHPContainer");
+  SubjectProc *sproc = QtGuiContext::getQtCurrent()->getSubjectProc();
+  YASSERT(sproc);
+  SubjectContainerBase *scont = 0;
+  while (!scont)
+    {
+      std::stringstream name;
+      long newid = GuiContext::getCurrent()->getNewId();
+      if (newid > 100000) break;
+      name.str("");
+      name << "container" << newid;
+      scont = sproc->addHPContainer(name.str());
+    }
+}
+
 void GuiEditor::CreateComponentInstance()
 {
   DEBTRACE("GuiEditor::CreateComponentInstance");
@@ -372,7 +389,7 @@ SubjectDataPort*  GuiEditor::CreateOutputPort(SubjectElementaryNode* seNode,
 /*!
  * Subject shrink or expand, command from popup menu: needs a valid selection
  */
-void GuiEditor::shrinkExpand() {
+void GuiEditor::shrinkExpand(Qt::KeyboardModifiers kbModifiers) {
   DEBTRACE("GuiEditor::shrinkExpand");
 
   Subject* sub = QtGuiContext::getQtCurrent()->getSelectedSubject();
@@ -393,12 +410,14 @@ void GuiEditor::shrinkExpand() {
     return;
   };
 
-  if (sni->isExpanded()) {
-    sni->setExpanded(false);
-  } else {
-    sni->setExpanded(true);
-  };
-  sni->reorganizeShrinkExpand();
+  ShrinkMode aShrinkMode = CurrentNode;
+  if (kbModifiers == Qt::ControlModifier) {
+    aShrinkMode = ElementaryNodes;
+  } else if (kbModifiers == (Qt::ShiftModifier|Qt::ControlModifier)) {
+    aShrinkMode = ChildrenNodes;
+  }
+
+  sni->reorganizeShrinkExpand(aShrinkMode);
   sni->showOutScopeLinks();
   sni->updateLinks();
 }
@@ -437,6 +456,8 @@ void GuiEditor::DeleteSubject(Subject* parent,
   toRemove->askRegisterUndoDestroy();
   if(!parent->destroy(toRemove))
     Message mess;
+  // Empty the clipboard in order to avoid the copy of a destroyed object.
+  QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL);
 }
 
 void GuiEditor::CutSubject()
@@ -543,6 +564,7 @@ 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];
@@ -550,7 +572,7 @@ void GuiEditor::PutGraphInNode(std::string typeNode)
   SubjectNode * snode = CreateNode(typeNode);
   // put the built bloc into target node
   sbloc->putInComposedNode(snode->getName(), typeNode);
-  // arrange local nodes in Proc
+  // select a target node
   YACS::HMI::SubjectProc* subproc = QtGuiContext::getQtCurrent()->getSubjectProc();
   QtGuiContext::getQtCurrent()->setSelectedSubject(subproc);
   arrangeNodes(false);
@@ -579,11 +601,21 @@ std::string GuiEditor::PutGraphInBloc()
   std::string blocname = tryname.str();
 
   //put one by one the child nodes of Proc node into a new Bloc node
-  SubjectNode * snode;
+  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)
@@ -591,11 +623,26 @@ std::string GuiEditor::PutGraphInBloc()
       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();
     }
-  // arrange local nodes in Proc
+  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);
-  arrangeNodes(false);
   return blocname;
 }
 
@@ -669,7 +716,7 @@ void GuiEditor::showRedo(QWidget *parent)
 QString GuiEditor::asciiFilter(const QString & name)
 {
   DEBTRACE(name.toStdString());
-  string aName = name.toAscii().data();
+  string aName = name.toLatin1().data();
   DEBTRACE(aName);
   for (int i=0; i < aName.size(); i++)
     {