Salome HOME
Return deleted code.
[modules/yacs.git] / src / genericgui / GenericGui.cxx
index 4975ee469933aecb6794cec2f06c68492caccdcc..cd53c27745cee1ab47816f7c8fb2e85f97699e28 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2006-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2016  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
@@ -67,7 +67,7 @@
 
 #include <ctime>
 
-#ifdef WNT
+#ifdef WIN32
 #define WEXITSTATUS(w)  ((int) ((w) & 0x40000000))
 #endif
 
@@ -153,15 +153,18 @@ GenericGui::GenericGui(YACS::HMI::SuitWrapper* wrapper, QMainWindow *parent)
   _dwTree = new QDockWidget(_parent);
   _dwTree->setVisible(false);
   _dwTree->setWindowTitle("Tree View: edition mode");
+  _dwTree->setObjectName("yacsTreeViewDock");
   _parent->addDockWidget(Qt::LeftDockWidgetArea, _dwTree);
   _dwStacked = new QDockWidget(_parent);
   _dwStacked->setVisible(false);
   _dwStacked->setWindowTitle("Input Panel");
+  _dwStacked->setObjectName("yacsInputPanelDock");
   _dwStacked->setMinimumWidth(270); // --- force a minimum until display
   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwStacked);
   _dwCatalogs = new QDockWidget(_parent);
   _dwCatalogs->setVisible(false);
   _dwCatalogs->setWindowTitle("Catalogs");
+  _dwCatalogs->setObjectName("yacsCatalogsDock");
   _parent->addDockWidget(Qt::RightDockWidgetArea, _dwCatalogs);
   _catalogsWidget = new CatalogWidget(_dwCatalogs,
                                       _builtinCatalog,
@@ -169,7 +172,8 @@ GenericGui::GenericGui(YACS::HMI::SuitWrapper* wrapper, QMainWindow *parent)
   _dwCatalogs->setWidget(_catalogsWidget);
 
   _parent->tabifyDockWidget(_dwStacked, _dwCatalogs);
-  _parent->tabifyDockWidget(_dwTree, _wrapper->objectBrowser());
+  if (_wrapper->objectBrowser())
+    _parent->tabifyDockWidget(_dwTree, _wrapper->objectBrowser());
 #if QT_VERSION >= 0x040500
   _parent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
 #endif
@@ -237,8 +241,8 @@ void GenericGui::createActions()
                                                 tr("Load Schema to run"), tr("Load a schema for run"),
                                                 0, _parent, false, this,  SLOT(onLoadAndRunSchema()));
 
-  _chooseBatchJobAct = _wrapper->createAction(getMenuId(), tr("Choose Batch Job for watch"), QIcon("icons:batch.png"),
-                                         tr("Choose Batch Job for watch"), tr("Choose Batch Job for watch"),
+  _chooseBatchJobAct = _wrapper->createAction(getMenuId(), tr("Choose Batch Job to watch"), QIcon("icons:batch.png"),
+                                         tr("Choose Batch Job to watch"), tr("Choose Batch Job to watch"),
                                          0, _parent, false, this,  SLOT(onChooseBatchJob()));
 
   _startResumeAct = _wrapper->createAction(getMenuId(), tr("Start or Resume Schema execution"), QIcon("icons:suspend_resume.png"),
@@ -304,6 +308,10 @@ void GenericGui::createActions()
                                             tr("Create Container"), tr("Create a New Container"),
                                             0, _parent, false, this,  SLOT(onNewContainer()));
 
+  _newHPContainerAct = _wrapper->createAction(getMenuId(), tr("Create a New HP Container"), QIcon("icons:container.png"),
+                                              tr("Create HP Container"), tr("Create a New Homogeneous Pool Container."),
+                                              0, _parent, false, this,  SLOT(onNewHPContainer()));
+
   _selectComponentInstanceAct = _wrapper->createAction(getMenuId(), tr("Select a Component Instance"), QIcon("icons:icon_select.png"),
                                                        tr("Select a Component Instance"), tr("Select a Component Instance"),
                                                        0, _parent, false, this,  SLOT(onSelectComponentInstance()));
@@ -416,6 +424,22 @@ void GenericGui::createActions()
                                          tr("Put node in block"), tr("Put node in block"),
                                          0, _parent, false, this,  SLOT(onPutInBloc()));
 
+  _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"),
                                                  0, _parent, false, this,  SLOT(onArrangeLocalNodes()));
@@ -441,6 +465,14 @@ void GenericGui::createActions()
                                             tr("shrink/expand"), tr("shrink or expand the selected node"),
                                             0, _parent, false, this,  SLOT(onShrinkExpand()));
 
+  _shrinkExpandChildren = _wrapper->createAction(getMenuId(), tr("shrink or expand direct children of the selected node"), QIcon("icons:shrinkExpand.png"),
+                                            tr("shrink/expand children"), tr("shrink or expand direct children of the selected node"),
+                                            0, _parent, false, this,  SLOT(onShrinkExpandChildren()));
+
+  _shrinkExpandElementaryRecursively = _wrapper->createAction(getMenuId(), tr("shrink or expand elementary nodes of the selected node recursively"), QIcon("icons:shrinkExpand.png"),
+                                            tr("shrink/expand elementary"), tr("shrink or expand elementary nodes of the selected node recursively"),
+                                            0, _parent, false, this,  SLOT(onShrinkExpandElementaryRecursively()));
+
   _toggleStraightLinksAct = _wrapper->createAction(getMenuId(), tr("draw straight or orthogonal links"), QIcon("icons:straightLink.png"),
                                                    tr("straight/orthogonal"), tr("draw straight or orthogonal links"),
                                                    0, _parent, true, this,  SLOT(onToggleStraightLinks(bool)));
@@ -651,7 +683,7 @@ void GenericGui::createMenus()
 
 void GenericGui::createTools()
 {
-  int aToolId = _wrapper->createTool ( tr( "YACS Toolbar" ) );
+  int aToolId = _wrapper->createTool ( tr( "YACS Toolbar" ), QString( "YACSToolbar" ) );
   _wrapper->createTool( _newSchemaAct, aToolId );
   _wrapper->createTool( _importSchemaAct, aToolId );
   _wrapper->createTool( _wrapper->separator(), aToolId );
@@ -701,6 +733,14 @@ void GenericGui::initialMenus()
   showBaseMenus(true);
 }
 
+void GenericGui::hideAllMenus()
+{
+  showBaseMenus   (false);
+  showCommonMenus (false);
+  showEditionMenus(false);
+  showExecMenus   (false);
+}
+
 void GenericGui::showBaseMenus(bool show)
 {
   DEBTRACE("GenericGui::showBaseMenus " << show);
@@ -782,12 +822,12 @@ void GenericGui::showCommonMenus(bool show)
   _wrapper->setToolShown(_hideAllLinksAct, show);
 }
 
-void GenericGui::switchContext(QWidget *view)
+void GenericGui::switchContext(QWidget *view, bool onExit)
 {
   DEBTRACE("GenericGui::switchContext " << view);
   if (! _mapViewContext.count(view))
     {
-      initialMenus();
+      onExit ? hideAllMenus() : initialMenus();
       _dwTree->setWidget(0);
       _dwStacked->setWidget(0);
       return;
@@ -929,19 +969,15 @@ bool GenericGui::closeContext(QWidget *view, bool onExit)
           break;
         }
     }
-  int studyId = _wrapper->activeStudyId();
-  if (context->getStudyId() == studyId)
+  _wrapper->deleteSchema(view);
+  DEBTRACE("delete context");
+  if (GuiExecutor* exec = context->getGuiExecutor())
     {
-      _wrapper->deleteSchema(view);
-      DEBTRACE("delete context");
-      if (GuiExecutor* exec = context->getGuiExecutor())
-        {
-          exec->closeContext();
-        }
-      delete context;
-      _mapViewContext.erase(view);
-      switchContext(newView);
+      exec->closeContext();
     }
+  delete context;
+  _mapViewContext.erase(view);
+  switchContext(newView, onExit);
   return true;
 }
 
@@ -1053,11 +1089,7 @@ void GenericGui::createContext(YACS::ENGINE::Proc* proc,
   GraphicsView* gView = new GraphicsView(viewWindow);
   gView->setScene(scene);
   gView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
-  int studyId = _wrapper->AssociateViewToWindow(gView, viewWindow);
-  context->setStudyId(studyId);
-  std::ostringstream value;
-  value << studyId;
-  proc->setProperty("DefaultStudyID",value.str());
+  _wrapper->AssociateViewToWindow(gView, viewWindow);
   context->setScene(scene);
   context->setView(gView);
   context->setWindow(viewWindow);
@@ -1186,6 +1218,7 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
 {
   DEBTRACE("GenericGui::setLoadedPresentation");
   QtGuiContext::getQtCurrent()->setLoadingPresentation(true);
+  map<SceneNodeItem*, QPointF> nodesToMove;
   map<YACS::ENGINE::Node*, PrsData> presNodes = _loader->getPrsData(proc);
   if (!presNodes.empty())
     {
@@ -1203,11 +1236,38 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
           inode->setWidth(pres._width);
           inode->setHeight(pres._height);
           inode->setExpanded(pres._expanded);
-          inode->setExpandedPos(QPointF(pres._expx, pres._expy));
+          QPointF anExpandedPos = QPointF(pres._expx, pres._expy);
+          if (anExpandedPos.isNull())
+              anExpandedPos = inode->pos();
+          inode->setExpandedPos(anExpandedPos);
           inode->setExpandedWH(pres._expWidth, pres._expHeight);
           inode->setShownState(shownState(pres._shownState));
+
+          // collect nodes to correct it's Y-position if this collides with parent's header
+          if (inode->getParent() ) {
+              qreal anX = inode->x();
+              qreal anY = inode->y();
+              if (inode->getShownState() == shrinkHidden) {
+                anX = inode->getExpandedX();
+                anY = inode->getExpandedY();
+              }
+              if (anY < inode->getParent()->getHeaderBottom())
+                nodesToMove[inode] = QPointF(anX, inode->getParent()->getHeaderBottom()+1);
+            }
         }
     }
+  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
+  
+  //after loading of presentation:
+
+  //move nodes because of progress bar, if any was added
+  map<SceneNodeItem*, QPointF>::iterator it = nodesToMove.begin();
+  for (; it!= nodesToMove.end(); ++it)
+    {
+      (*it).first->setTopLeft((*it).second);
+    }
+
+  //update links
   if (Scene::_autoComputeLinks)
     _guiEditor->rebuildLinks();
   else
@@ -1217,8 +1277,6 @@ void GenericGui::setLoadedPresentation(YACS::ENGINE::Proc* proc)
       SceneComposedNodeItem *proc = dynamic_cast<SceneComposedNodeItem*>(item);
       proc->updateLinks();
     }
-
-  QtGuiContext::getQtCurrent()->setLoadingPresentation(false);
 }
 
 // -----------------------------------------------------------------------------
@@ -1249,7 +1307,7 @@ void GenericGui::loadSchema(const std::string& filename,bool edit, bool arrangeL
     {
       DEBTRACE(logger->getStr());
     }
-  QString fn=QString::fromStdString(filename);
+  QString fn=QString::fromUtf8(filename.c_str());
   if(edit)
     createContext(proc, fn, "", true);
   else
@@ -1289,11 +1347,11 @@ void GenericGui::onImportSchema()
       if (!fi.exists() && fi.suffix() != "xml")
         fn += ".xml";
 
-      DEBTRACE("file loaded : " <<fn.toStdString());
+      DEBTRACE("file loaded : " <<fn.toUtf8().constData());
       YACS::ENGINE::Proc *proc = 0;
 
       try {
-         proc = _loader->load(fn.toLatin1());
+         proc = _loader->load(fn.toUtf8().constData());
       }
       catch (...) {
       }
@@ -1353,7 +1411,7 @@ void GenericGui::onImportSupervSchema()
   QString tmpFileName;
   try
     {
-#ifdef WNT
+#ifdef WIN32
       QString tmpDir = getenv("TEMP");
          QString fileExt = "bat";
 #else
@@ -1372,11 +1430,11 @@ void GenericGui::onImportSupervSchema()
       QString aCall = "salomeloader."+ fileExt+ " "+ fn + " " + tmpFileName + " > " + tmpOutput;
       DEBTRACE(aCall.toStdString());
       
-      int ret = system(aCall.toAscii());
+      int ret = system(aCall.toLatin1());
       if(ret != 0)
         {
           // --- read file with logs
-          fstream f(tmpOutput.toAscii());
+          fstream f(tmpOutput.toLatin1());
           stringstream hfile;
           hfile << f.rdbuf();
           f.close();
@@ -1451,8 +1509,8 @@ QString GenericGui::getSaveFileName(const QString& fileName)
   filters << "XML files (*.xml)"
           << "Any files (*)";
   dialog.setFileMode(QFileDialog::AnyFile);
-  dialog.setFilters(filters);
-  dialog.selectFilter("(*.xml)");
+  dialog.setNameFilters(filters);
+  dialog.selectNameFilter("(*.xml)");
   dialog.setDefaultSuffix("xml");
   dialog.setConfirmOverwrite(true);
   //dialog.setConfirmOverwrite(false);  // bug Qt4.3.3
@@ -1487,12 +1545,12 @@ void GenericGui::onExportSchema()
     }
   if (fn.isEmpty()) return;
 
-  DEBTRACE("GenericGui::onExportSchema: " << fn.toStdString());
+  DEBTRACE("GenericGui::onExportSchema: " << fn.toUtf8().constData());
   //to be sure that all pending changes are effective
   _parent->setFocus();
   QtGuiContext::getQtCurrent()->setFileName(fn);
   VisitorSaveGuiSchema aWriter(proc);
-  aWriter.openFileSchema( fn.toStdString() );
+  aWriter.openFileSchema( fn.toUtf8().constData() );
   aWriter.visitProc();
   aWriter.closeFileSchema();
   QtGuiContext::getQtCurrent()->setNotSaved(false);
@@ -1513,10 +1571,10 @@ void GenericGui::onExportSchemaAs()
   QString fn = getSaveFileName(fo);
   if (fn.isEmpty()) return;
 
-  DEBTRACE("GenericGui::onExportSchemaAs: " << fn.toStdString());
+  DEBTRACE("GenericGui::onExportSchemaAs: " << fn.toUtf8().constData());
   QtGuiContext::getQtCurrent()->setFileName(fn);
   VisitorSaveGuiSchema aWriter(proc);
-  aWriter.openFileSchema(fn.toStdString());
+  aWriter.openFileSchema(fn.toUtf8().constData());
   aWriter.visitProc();
   aWriter.closeFileSchema();
   _isSaved = true;
@@ -1599,7 +1657,7 @@ void GenericGui::onRunLoadedSchema(bool withState)
   QFileInfo fo = QtGuiContext::getQtCurrent()->getFileName();
   QString procName = fo.baseName();
   //QString tmpDir = SALOMEDS_Tool::GetTmpDir().c_str();
-#ifdef WNT
+#ifdef WIN32
   QString tmpDir = getenv("TEMP");
 #else
   QString tmpDir = "/tmp";
@@ -1898,6 +1956,12 @@ void GenericGui::onNewContainer()
   _guiEditor->CreateContainer();
 }
 
+void GenericGui::onNewHPContainer()
+{
+  DEBTRACE("GenericGui::onNewHPContainer");
+  _guiEditor->CreateHPContainer();
+}
+
 void GenericGui::onNewSalomeComponent()
 {
   DEBTRACE("GenericGui::onNewSalomeComponent");
@@ -2063,6 +2127,37 @@ 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->PutGraphInNode("ForEachLoop_"+type);
+}
+
+void GenericGui::onPutGraphInWhileLoop()
+{
+  DEBTRACE("GenericGui::onPutGraphInWhileLoop");
+  _guiEditor->PutGraphInNode("WhileLoop");
+}
+
+void GenericGui::onPutGraphInOptimizerLoop()
+{
+  DEBTRACE("GenericGui::onPutGraphInOptimizerLoop");
+  _guiEditor->PutGraphInNode("OptimizerLoop");
+}
+
 void GenericGui::onArrangeLocalNodes()
 {
   DEBTRACE("GenericGui::onArrangeLocalNodes");
@@ -2098,6 +2193,16 @@ void GenericGui::onShrinkExpand() {
   _guiEditor->shrinkExpand();
 }
 
+void GenericGui::onShrinkExpandChildren() {
+  DEBTRACE("GenericGui::onShrinkExpandChildren");
+  _guiEditor->shrinkExpand(Qt::ControlModifier|Qt::ShiftModifier);
+}
+
+void GenericGui::onShrinkExpandElementaryRecursively() {
+  DEBTRACE("GenericGui::onShrinkExpandElementaryRecursively");
+  _guiEditor->shrinkExpand(Qt::ControlModifier);
+}
+
 void GenericGui::onToggleStraightLinks(bool checked)
 {
   Scene::_straightLinks = checked;
@@ -2443,7 +2548,11 @@ void GenericGui::onUndo()
 {
   DEBTRACE("GenericGui::onUndo");
   if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
+  {
     QtGuiContext::getQtCurrent()->getInvoc()->undo();
+    // Empty the clipboard in order to avoid the copy of a destroyed object.
+    QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL);
+  }
   else Message("undo not possible when there are local modifications not confirmed");
 }
 
@@ -2451,7 +2560,11 @@ void GenericGui::onRedo()
 {
   DEBTRACE("GenericGui::onRedo");
   if (QtGuiContext::getQtCurrent()->_setOfModifiedSubjects.empty())
+  {
     QtGuiContext::getQtCurrent()->getInvoc()->redo();
+    // Empty the clipboard in order to avoid the copy of a destroyed object.
+    QtGuiContext::getQtCurrent()->setSubjectToCopy(NULL);
+  }
   else Message("redo not possible when there are local modifications not confirmed");
 }
 
@@ -2468,7 +2581,6 @@ void GenericGui::onShowRedo()
 void GenericGui::onCleanOnExit()
 {
   DEBTRACE("GenericGui::onCleanOnExit");
-  int studyId = _wrapper->activeStudyId();
   map<QWidget*, YACS::HMI::QtGuiContext*> mapViewContextCopy = _mapViewContext;
   map<QWidget*, YACS::HMI::QtGuiContext*>::iterator it = mapViewContextCopy.begin();
   for (; it != mapViewContextCopy.end(); ++it)